Initial commit for MOBFIRST-22354 Star story.
This commit is contained in:
parent
29c5aa3377
commit
0f655b534e
@ -199,6 +199,8 @@
|
||||
94CA227D24058534002D6750 /* VerizonNHGeDS-Regular.otf in Resources */ = {isa = PBXBuildFile; fileRef = 94CA227924058533002D6750 /* VerizonNHGeDS-Regular.otf */; };
|
||||
94CA227E24058534002D6750 /* VerizonNHGeDS-Bold.otf in Resources */ = {isa = PBXBuildFile; fileRef = 94CA227A24058533002D6750 /* VerizonNHGeDS-Bold.otf */; };
|
||||
94F6516D2437954100631BF9 /* Tabs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94F6516C2437954100631BF9 /* Tabs.swift */; };
|
||||
AA07EA912510A442009A2AE3 /* StarModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA07EA902510A442009A2AE3 /* StarModel.swift */; };
|
||||
AA07EA932510A451009A2AE3 /* Star.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA07EA922510A451009A2AE3 /* Star.swift */; };
|
||||
AA0A257824766C8A00862F64 /* ListLeftVariableIconWithRightCaretBodyTextModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA0A257724766C8A00862F64 /* ListLeftVariableIconWithRightCaretBodyTextModel.swift */; };
|
||||
AA0A257A24766CA200862F64 /* ListLeftVariableIconWithRightCaretBodyText.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA0A257924766CA200862F64 /* ListLeftVariableIconWithRightCaretBodyText.swift */; };
|
||||
AA104AC724472DB0004D2810 /* HeadersH1Button.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA104AC624472DB0004D2810 /* HeadersH1Button.swift */; };
|
||||
@ -687,6 +689,8 @@
|
||||
94CA227A24058533002D6750 /* VerizonNHGeDS-Bold.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "VerizonNHGeDS-Bold.otf"; sourceTree = "<group>"; };
|
||||
94CA227B24058533002D6750 /* VerizonNHGeTX-Regular.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "VerizonNHGeTX-Regular.otf"; sourceTree = "<group>"; };
|
||||
94F6516C2437954100631BF9 /* Tabs.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Tabs.swift; sourceTree = "<group>"; };
|
||||
AA07EA902510A442009A2AE3 /* StarModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StarModel.swift; sourceTree = "<group>"; };
|
||||
AA07EA922510A451009A2AE3 /* Star.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Star.swift; sourceTree = "<group>"; };
|
||||
AA0A257724766C8A00862F64 /* ListLeftVariableIconWithRightCaretBodyTextModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListLeftVariableIconWithRightCaretBodyTextModel.swift; sourceTree = "<group>"; };
|
||||
AA0A257924766CA200862F64 /* ListLeftVariableIconWithRightCaretBodyText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListLeftVariableIconWithRightCaretBodyText.swift; sourceTree = "<group>"; };
|
||||
AA104AC624472DB0004D2810 /* HeadersH1Button.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeadersH1Button.swift; sourceTree = "<group>"; };
|
||||
@ -1875,6 +1879,8 @@
|
||||
D20492A524329CE200A5EED6 /* LoadImageView.swift */,
|
||||
0A51F3E02475CB73002E08B6 /* LoadingSpinnerModel.swift */,
|
||||
0A51F3E12475CB73002E08B6 /* LoadingSpinner.swift */,
|
||||
AA07EA902510A442009A2AE3 /* StarModel.swift */,
|
||||
AA07EA922510A451009A2AE3 /* Star.swift */,
|
||||
);
|
||||
path = Views;
|
||||
sourceTree = "<group>";
|
||||
@ -2306,6 +2312,7 @@
|
||||
AA1EC59724373985003D6F50 /* ListThreeColumnSpeedTestDividerModel.swift in Sources */,
|
||||
BB1D17E0244EAA30001D2002 /* ListDeviceComplexButtonMediumModel.swift in Sources */,
|
||||
D2CAC7D3251105A700C75681 /* MVMCoreUITopAlertExpandableView+Extension.swift in Sources */,
|
||||
AA07EA932510A451009A2AE3 /* Star.swift in Sources */,
|
||||
D29DF2CF21E7C104003B2FB9 /* MFLoadingViewController.m in Sources */,
|
||||
D28A837B23C928DA00DFE4FC /* MoleculeListCellProtocol.swift in Sources */,
|
||||
D28BA74D248589C800B75CB8 /* TabPageModelProtocol.swift in Sources */,
|
||||
@ -2569,6 +2576,7 @@
|
||||
BB2BF0EC2452A9D5001D0FC2 /* ListDeviceComplexButtonSmallModel.swift in Sources */,
|
||||
943784F6236B77BB006A1E82 /* WheelAnimationHandler.swift in Sources */,
|
||||
011D95A1240453D0000E3791 /* RuleEqualsModel.swift in Sources */,
|
||||
AA07EA912510A442009A2AE3 /* StarModel.swift in Sources */,
|
||||
D29DF2AA21E7B2F9003B2FB9 /* MVMCoreUIConstants.m in Sources */,
|
||||
011D95892404249B000E3791 /* FormHolderModelProtocol.swift in Sources */,
|
||||
BB54C5202434D92F0038326C /* ListRightVariableButtonAllTextAndLinks.swift in Sources */,
|
||||
|
||||
111
MVMCoreUI/Atomic/Atoms/Views/Star.swift
Normal file
111
MVMCoreUI/Atomic/Atoms/Views/Star.swift
Normal file
@ -0,0 +1,111 @@
|
||||
//
|
||||
// Star.swift
|
||||
// MVMCoreUI
|
||||
//
|
||||
// Created by Lekshmi S on 15/09/20.
|
||||
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
@objcMembers open class Star: View {
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Properties
|
||||
//--------------------------------------------------
|
||||
private var starLayer: CAShapeLayer?
|
||||
let maskLayer = CAShapeLayer()
|
||||
|
||||
var starModel: StarModel?
|
||||
var progressBar = ProgressBar(frame: CGRect(x: 0, y: 0, width: 30, height: 30))
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Constraints
|
||||
//--------------------------------------------------
|
||||
public var widthConstraint: NSLayoutConstraint?
|
||||
public var heightConstraint: NSLayoutConstraint?
|
||||
|
||||
//------------------------------------------------------
|
||||
// MARK: - State Handling
|
||||
//------------------------------------------------------
|
||||
|
||||
open override func draw(_ rect: CGRect) {
|
||||
//Draw the heart
|
||||
starLayer?.removeFromSuperlayer()
|
||||
let star = drawStar()
|
||||
layer.addSublayer(star)
|
||||
starLayer = star
|
||||
|
||||
//Mask the star
|
||||
maskLayer.removeFromSuperlayer()
|
||||
maskLayer.path = star.path
|
||||
self.layer.mask = maskLayer
|
||||
}
|
||||
|
||||
func drawStar() -> CAShapeLayer {
|
||||
let shapeLayer = CAShapeLayer()
|
||||
shapeLayer.frame = self.bounds
|
||||
let starPath = UIBezierPath()
|
||||
let center = shapeLayer.position
|
||||
let theta = .pi / CGFloat(5.0)
|
||||
let outerRadius = center.x * 1.039
|
||||
let excessRadius = outerRadius - center.x
|
||||
let innerRadius = CGFloat(outerRadius * 0.382)
|
||||
let leftEdgePointX = (center.x + cos(4.0 * theta) * outerRadius) + excessRadius
|
||||
let horizontalOffset = leftEdgePointX / 2.0
|
||||
let offsetCenter = CGPoint(x: center.x - horizontalOffset, y: center.y)
|
||||
for i in 0 ..< 10 {
|
||||
let radius = i % 2 == 0 ? outerRadius : innerRadius
|
||||
let pointX = offsetCenter.x + cos(CGFloat(i) * theta) * radius
|
||||
let pointY = offsetCenter.y + sin(CGFloat(i) * theta) * radius
|
||||
let point = CGPoint(x: pointX, y: pointY)
|
||||
if i == 0 {
|
||||
starPath.move(to: point)
|
||||
} else {
|
||||
starPath.addLine(to: point)
|
||||
}
|
||||
}
|
||||
starPath.close()
|
||||
// Rotate the path so the star points up as expected
|
||||
var pathTransform = CGAffineTransform.identity
|
||||
pathTransform = pathTransform.translatedBy(x: center.x, y: center.y)
|
||||
pathTransform = pathTransform.rotated(by: CGFloat(-.pi / 2.0))
|
||||
pathTransform = pathTransform.translatedBy(x: -center.x, y: -center.y)
|
||||
starPath.apply(pathTransform)
|
||||
shapeLayer.path = starPath.cgPath
|
||||
shapeLayer.fillColor = UIColor.clear.cgColor
|
||||
shapeLayer.opacity = 1.0
|
||||
shapeLayer.lineWidth = 1
|
||||
shapeLayer.strokeColor = starModel?.borderColor.cgColor
|
||||
return shapeLayer
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Lifecycle
|
||||
//--------------------------------------------------
|
||||
open override func setupView() {
|
||||
super.setupView()
|
||||
addSubview(progressBar)
|
||||
NSLayoutConstraint.constraintPinSubview(toSuperview: progressBar)
|
||||
}
|
||||
|
||||
public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||
super.set(with: model, delegateObject, additionalData)
|
||||
guard let model = model as? StarModel else { return }
|
||||
self.starModel = model
|
||||
progressBar.progress = Float((model.percent) / 100.0)
|
||||
progressBar.progressTintColor = model.fillColor.uiColor
|
||||
progressBar.trackTintColor = .mvmWhite
|
||||
setSizeForProgressBar(size: model.size)
|
||||
}
|
||||
|
||||
func setSizeForProgressBar(size: CGFloat) {
|
||||
progressBar.transform = progressBar.transform.scaledBy(x: 1, y: size/9)
|
||||
progressBar.transform = progressBar.transform.translatedBy(x: 0, y: -3.5)
|
||||
widthConstraint = widthAnchor.constraint(equalToConstant: size)
|
||||
widthConstraint?.isActive = true
|
||||
heightConstraint = heightAnchor.constraint(equalTo: widthAnchor, multiplier: 1)
|
||||
heightConstraint?.isActive = true
|
||||
setNeedsDisplay()
|
||||
}
|
||||
}
|
||||
65
MVMCoreUI/Atomic/Atoms/Views/StarModel.swift
Normal file
65
MVMCoreUI/Atomic/Atoms/Views/StarModel.swift
Normal file
@ -0,0 +1,65 @@
|
||||
//
|
||||
// StarModel.swift
|
||||
// MVMCoreUI
|
||||
//
|
||||
// Created by Lekshmi S on 15/09/20.
|
||||
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
open class StarModel: MoleculeModelProtocol {
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Properties
|
||||
//--------------------------------------------------
|
||||
public static var identifier: String = "star"
|
||||
public var backgroundColor: Color?
|
||||
@Percent public var percent: CGFloat = 0
|
||||
public var borderColor: Color = Color(uiColor: .mvmBlack)
|
||||
public var fillColor: Color = Color(uiColor: .mvmBlack)
|
||||
public var size: CGFloat = 30.0
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Keys
|
||||
//--------------------------------------------------
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case moleculeName
|
||||
case backgroundColor
|
||||
case percent
|
||||
case borderColor
|
||||
case fillColor
|
||||
case size
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Codec
|
||||
//--------------------------------------------------
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
|
||||
if let percent = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .percent) {
|
||||
self.percent = percent
|
||||
}
|
||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||
if let borderColor = try typeContainer.decodeIfPresent(Color.self, forKey: .borderColor) {
|
||||
self.borderColor = borderColor
|
||||
}
|
||||
if let fillColor = try typeContainer.decodeIfPresent(Color.self, forKey: .fillColor) {
|
||||
self.fillColor = fillColor
|
||||
}
|
||||
if let size = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .size) {
|
||||
self.size = size
|
||||
}
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||
try container.encode(moleculeName, forKey: .moleculeName)
|
||||
try container.encodeIfPresent(percent, forKey: .percent)
|
||||
try container.encodeIfPresent(borderColor, forKey: .borderColor)
|
||||
try container.encodeIfPresent(fillColor, forKey: .fillColor)
|
||||
try container.encodeIfPresent(size, forKey: .size)
|
||||
}
|
||||
}
|
||||
@ -87,7 +87,7 @@ import Foundation
|
||||
MoleculeObjectMapping.shared()?.register(viewClass: RadioSwatches.self, viewModelClass: RadioSwatchesModel.self)
|
||||
MoleculeObjectMapping.shared()?.register(viewClass: Tags.self, viewModelClass: TagsModel.self)
|
||||
MoleculeObjectMapping.shared()?.register(viewClass: Tag.self, viewModelClass: TagModel.self)
|
||||
|
||||
MoleculeObjectMapping.shared()?.register(viewClass: Star.self, viewModelClass: StarModel.self)
|
||||
|
||||
|
||||
// MARK:- Other Atoms
|
||||
|
||||
Loading…
Reference in New Issue
Block a user