From be426c756fb10c5e41d03127623a1ee6c2de0c97 Mon Sep 17 00:00:00 2001 From: Subhankar Date: Wed, 27 Jan 2021 22:30:06 +0530 Subject: [PATCH 1/8] scope modification for product detail molecule --- .../Molecules/VerticalCombinationViews/HeadlineBody.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/HeadlineBody.swift b/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/HeadlineBody.swift index d111d1c5..ba95a5d3 100644 --- a/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/HeadlineBody.swift +++ b/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/HeadlineBody.swift @@ -54,7 +54,7 @@ open class HeadlineBody: View { } } - func styleLandingPageHeader() { + public func styleLandingPageHeader() { headlineLabel.setFontStyle(.Title2XLarge) messageLabel.setFontStyle(.RegularBodySmall) spaceBetweenLabelsConstant = PaddingTwo From 740e757fe4fb23e3c06ec88b55009e774b9626a8 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 10 Feb 2021 13:53:58 -0500 Subject: [PATCH 2/8] undelrine didn't show when rotating --- .../Atomic/Atoms/Buttons/Link/Link.swift | 30 ++++++++----------- .../Atomic/Atoms/Buttons/Link/LinkModel.swift | 4 +-- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/Link/Link.swift b/MVMCoreUI/Atomic/Atoms/Buttons/Link/Link.swift index 9ced5f5a..04140d6e 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/Link/Link.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/Link/Link.swift @@ -11,18 +11,18 @@ import UIKit @objcMembers open class Link: Button { //-------------------------------------------------- - // MARK: - Lifecycle + // MARK: - Draw //-------------------------------------------------- open override func draw(_ rect: CGRect) { - guard let textRect = titleLabel?.frame else { return } - - let context = UIGraphicsGetCurrentContext() + guard let textRect = titleLabel?.frame, + let context = UIGraphicsGetCurrentContext() + else { return } // Set line to the same color as the text if let color = titleLabel?.textColor?.cgColor { - context?.setStrokeColor(color) + context.setStrokeColor(color) } // x should be according to the text, not the button @@ -31,9 +31,9 @@ import UIKit // Line is 1 point below the text let y = textRect.origin.y + textRect.size.height + 1 - context?.move(to: CGPoint(x: x, y: y)) - context?.addLine(to: CGPoint(x: x + textRect.size.width, y: y)) - context?.strokePath() + context.move(to: CGPoint(x: x, y: y)) + context.addLine(to: CGPoint(x: x + textRect.size.width, y: y)) + context.strokePath() } open override var intrinsicContentSize: CGSize { @@ -67,16 +67,12 @@ extension Link { open override func updateView(_ size: CGFloat) { super.updateView(size) - DispatchQueue.main.async { [weak self] in - guard let self = self else { return } - - var width = size - if MVMCoreGetterUtility.fequal(a: Float.leastNormalMagnitude, b: Float(size)) { - width = MVMCoreUIUtility.getWidth() - } - - self.titleLabel?.font = MFStyler.fontB2(forWidth: width) + var width = size + if MVMCoreGetterUtility.fequal(a: Float.leastNormalMagnitude, b: Float(size)) { + width = MVMCoreUIUtility.getWidth() } + + titleLabel?.font = MFStyler.fontB2(forWidth: width) } open override func setupView() { diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/Link/LinkModel.swift b/MVMCoreUI/Atomic/Atoms/Buttons/Link/LinkModel.swift index 4519b030..f3b48bd4 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/Link/LinkModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/Link/LinkModel.swift @@ -14,9 +14,7 @@ open class LinkModel: ButtonModelProtocol, MoleculeModelProtocol, EnableableMode // MARK: - Properties //-------------------------------------------------- - public class var identifier: String { - return "link" - } + public class var identifier: String { "link" } public var backgroundColor: Color? public var accessibilityIdentifier: String? From a42063d925badd3c37b05dd06f55806e1c02b812 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 10 Feb 2021 17:08:30 -0500 Subject: [PATCH 3/8] accessibility --- .../Atomic/Molecules/HorizontalCombinationViews/TabBar.swift | 1 + .../Molecules/HorizontalCombinationViews/TabBarModel.swift | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TabBar.swift b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TabBar.swift index 14b7cf94..4a6e3ca7 100644 --- a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TabBar.swift +++ b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TabBar.swift @@ -54,6 +54,7 @@ var tabs: [UITabBarItem] = [] for (index, tab) in model.tabs.enumerated() { let tabBarItem = UITabBarItem(title: tab.title, image: MVMCoreCache.shared()?.getImageFromRegisteredBundles(tab.image), tag: index) + tabBarItem.accessibilityLabel = tab.accessibilityText if #available(iOS 13.0, *) { } else { tabBarItem.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -3) diff --git a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TabBarModel.swift b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TabBarModel.swift index 581b890e..fc3e9449 100644 --- a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TabBarModel.swift +++ b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TabBarModel.swift @@ -63,11 +63,13 @@ public class TabBarItemModel: Codable { var title: String? var image: String var action: ActionModelProtocol + var accessibilityText: String? private enum CodingKeys: String, CodingKey { case title case image case action + case accessibilityText } public init(with title: String?, image: String, action: ActionModelProtocol) { @@ -81,6 +83,7 @@ public class TabBarItemModel: Codable { title = try typeContainer.decodeIfPresent(String.self, forKey: .title) image = try typeContainer.decode(String.self, forKey: .image) action = try typeContainer.decodeModel(codingKey: .action) + accessibilityText = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityText) } public func encode(to encoder: Encoder) throws { @@ -88,5 +91,6 @@ public class TabBarItemModel: Codable { try container.encodeIfPresent(title, forKey: .title) try container.encode(image, forKey: .image) try container.encodeModel(action, forKey: .action) + try container.encodeIfPresent(accessibilityText, forKey: .accessibilityText) } } From f74fbc059c8b598f0645e943c8f2c9cfbb2f8ff3 Mon Sep 17 00:00:00 2001 From: "Khan, Arshad" Date: Thu, 11 Feb 2021 21:53:54 +0530 Subject: [PATCH 4/8] implementing feedback --- .../Molecules/VerticalCombinationViews/HeadlineBody.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/HeadlineBody.swift b/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/HeadlineBody.swift index f5c0c565..b3aed7fc 100644 --- a/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/HeadlineBody.swift +++ b/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/HeadlineBody.swift @@ -56,19 +56,19 @@ open class HeadlineBody: View { spaceBetweenLabelsConstant = Padding.Two } - func stylePageHeader() { + public func stylePageHeader() { headlineLabel.setFontStyle(.BoldTitleLarge) messageLabel.setFontStyle(.RegularBodySmall) spaceBetweenLabelsConstant = Padding.One } - func styleListItem() { + public func styleListItem() { headlineLabel.setFontStyle(.BoldBodySmall) messageLabel.setFontStyle(.RegularBodySmall) spaceBetweenLabelsConstant = 0 } - func styleListItemDivider() { + public func styleListItemDivider() { headlineLabel.setFontStyle(.BoldTitleMedium) messageLabel.setFontStyle(.RegularBodySmall) spaceBetweenLabelsConstant = 0 From 23a8c2c1baba15bd295bc32492b73fe7556964c0 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 11 Feb 2021 17:51:09 -0500 Subject: [PATCH 5/8] conflict update --- MVMCoreUI/Atomic/Atoms/Views/VideoDataManager.swift | 8 ++++---- MVMCoreUI/BaseControllers/ScrollingViewController.swift | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/VideoDataManager.swift b/MVMCoreUI/Atomic/Atoms/Views/VideoDataManager.swift index 046ba3bb..a4ba9235 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/VideoDataManager.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/VideoDataManager.swift @@ -12,7 +12,7 @@ import AVFoundation @objcMembers open class VideoDataManager: NSObject { /// The state of the video. - @objc public enum State: Int { + @objc public enum VideoState: Int { case none case loading case loaded @@ -23,13 +23,13 @@ import AVFoundation public var player: AVPlayer? // Thread Safe video state handling. - private var _videoState = State.none + private var _videoState = VideoState.none private let videoStatueQueue = DispatchQueue(label: "com.vzw.mvmcoreui.videoDataManager.state", attributes: .concurrent) /// The state of the video. Use KVO to listen for state changes. - @objc public var videoState: State { + @objc public var videoState: VideoState { get { - var state = State.none + var state = VideoState.none videoStatueQueue.sync { state = _videoState } diff --git a/MVMCoreUI/BaseControllers/ScrollingViewController.swift b/MVMCoreUI/BaseControllers/ScrollingViewController.swift index 9a9a42e3..19c9d001 100644 --- a/MVMCoreUI/BaseControllers/ScrollingViewController.swift +++ b/MVMCoreUI/BaseControllers/ScrollingViewController.swift @@ -73,7 +73,7 @@ open class ScrollingViewController: ViewController { scrollView.flashScrollIndicators() } - public func scrollViewDidScroll(_ scrollView: UIScrollView) { + open func scrollViewDidScroll(_ scrollView: UIScrollView) { executeBehaviors { (behavior: PageScrolledBehavior) in behavior.pageScrolled(scrollView: scrollView) } From 744398b7b8ac68cf1583054c09613dcc566c2f15 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 11 Feb 2021 19:44:24 -0500 Subject: [PATCH 6/8] Register class, remove debug --- MVMCoreUI/Atomic/Atoms/Views/VideoModel.swift | 3 +-- MVMCoreUI/Atomic/MoleculeObjectMapping.swift | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/VideoModel.swift b/MVMCoreUI/Atomic/Atoms/Views/VideoModel.swift index c64b13e5..8bc3d827 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/VideoModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/VideoModel.swift @@ -65,14 +65,13 @@ open class VideoModel: MoleculeModelProtocol { private func haltVideo() { guard !halted else { return } halted = true - print("halted \(video)") + guard videoDataManager.videoState == .loaded else { return } videoDataManager.player?.pause() } private func unhaltVideo() { guard halted else { return } halted = false - print("unhalted \(video)") guard videoDataManager.videoState == .loaded else { return } if alwaysReset { // Always start video at the beginning. diff --git a/MVMCoreUI/Atomic/MoleculeObjectMapping.swift b/MVMCoreUI/Atomic/MoleculeObjectMapping.swift index 559b611b..e4d3a59a 100644 --- a/MVMCoreUI/Atomic/MoleculeObjectMapping.swift +++ b/MVMCoreUI/Atomic/MoleculeObjectMapping.swift @@ -106,6 +106,7 @@ import Foundation MoleculeObjectMapping.shared()?.register(viewClass: RadioButtonLabel.self, viewModelClass: RadioButtonLabelModel.self) MoleculeObjectMapping.shared()?.register(viewClass: WebView.self, viewModelClass: WebViewModel.self) MoleculeObjectMapping.shared()?.register(viewClass: LoadingSpinner.self, viewModelClass: LoadingSpinnerModel.self) + MoleculeObjectMapping.shared()?.register(viewClass: Video.self, viewModelClass: VideoModel.self) // MARK:- Horizontal Combination Molecules MoleculeObjectMapping.shared()?.register(viewClass: StringAndMoleculeView.self, viewModelClass: StringAndMoleculeModel.self) @@ -151,6 +152,7 @@ import Foundation MoleculeObjectMapping.shared()?.register(viewClass: Scroller.self, viewModelClass: ScrollerModel.self) MoleculeObjectMapping.shared()?.register(viewClass: ModuleMolecule.self, viewModelClass: ModuleMoleculeModel.self) MoleculeObjectMapping.shared()?.register(viewClass: BGImageMolecule.self, viewModelClass: BGImageMoleculeModel.self) + MoleculeObjectMapping.shared()?.register(viewClass: BGVideoImageMolecule.self, viewModelClass: BGVideoImageMoleculeModel.self) MoleculeObjectMapping.shared()?.register(viewClass: MoleculeSectionHeader.self, viewModelClass: MoleculeSectionHeaderModel.self) MoleculeObjectMapping.shared()?.register(viewClass: MoleculeSectionFooter.self, viewModelClass: MoleculeSectionFooterModel.self) From 0793498e3f0a4038e8543792bf5e9da1a767c6a2 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 11 Feb 2021 20:31:17 -0500 Subject: [PATCH 7/8] Active listener --- MVMCoreUI/Atomic/Atoms/Views/Video.swift | 1 + MVMCoreUI/Atomic/Atoms/Views/VideoModel.swift | 36 +++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Video.swift b/MVMCoreUI/Atomic/Atoms/Views/Video.swift index f869ab06..92ff3ecf 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Video.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Video.swift @@ -51,6 +51,7 @@ open class Video: View { // Handle pause behavior model.addVisibleBehavior(for: self, delegateObject: delegateObject) model.addScrollBehavior(for: self, delegateObject: delegateObject) + model.addActiveListener(for: self, delegateObject: delegateObject) } /// Listens and responds to video loading state changes. diff --git a/MVMCoreUI/Atomic/Atoms/Views/VideoModel.swift b/MVMCoreUI/Atomic/Atoms/Views/VideoModel.swift index 8bc3d827..9b1d4f71 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/VideoModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/VideoModel.swift @@ -24,6 +24,8 @@ open class VideoModel: MoleculeModelProtocol { private weak var visibleBehavior: PageVisibilityClosureBehavior? private weak var scrollBehavior: PageScrolledClosureBehavior? + private var activeListener: Any? + private var resignActiveListener: Any? private enum CodingKeys: String, CodingKey { case moleculeName @@ -113,9 +115,8 @@ open class VideoModel: MoleculeModelProtocol { let onScroll = { [weak self] (scrollView: UIScrollView) in // If visible to not visible, pause video. // If not visible to visible, unpause if needed, add visible behavior - guard let self = self, - let containingView = (delegateObject?.moleculeDelegate as? UIViewController)?.view else { return } - if !MVMCoreUIUtility.isView(view, visibleIn: containingView) { + guard let self = self else { return } + if !MVMCoreUIUtility.isView(view, visibleIn: scrollView) { self.haltVideo() } else { self.unhaltVideo() @@ -132,4 +133,33 @@ open class VideoModel: MoleculeModelProtocol { delegate.add(behavior: scrollBehavior) self.scrollBehavior = scrollBehavior } + + open func addActiveListener(for view: Video, delegateObject: MVMCoreUIDelegateObject?) { + removeActiveListener() + + guard let containingView = (delegateObject?.moleculeDelegate as? UIViewController)?.view else { return } + resignActiveListener = NotificationCenter.default.addObserver(forName: UIApplication.willResignActiveNotification, object: nil, queue: OperationQueue.main) { [weak self] (notification) in + self?.haltVideo() + } + activeListener = NotificationCenter.default.addObserver(forName: UIApplication.didBecomeActiveNotification, object: nil, queue: OperationQueue.main) { [weak self] (notification) in + if MVMCoreUIUtility.isView(view, visibleIn: containingView) { + self?.unhaltVideo() + } + } + } + + private func removeActiveListener() { + if let observer = activeListener { + NotificationCenter.default.removeObserver(observer) + activeListener = nil + } + if let observer = resignActiveListener { + NotificationCenter.default.removeObserver(observer) + resignActiveListener = nil + } + } + + deinit { + removeActiveListener() + } } From ff96fd284a716ae21c88737d784821fe8a2b57a6 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Fri, 12 Feb 2021 11:46:05 -0500 Subject: [PATCH 8/8] load image needed --- MVMCoreUI/Atomic/Atoms/Views/LoadImageView.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/LoadImageView.swift b/MVMCoreUI/Atomic/Atoms/Views/LoadImageView.swift index aafddb00..8d8ef49e 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/LoadImageView.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/LoadImageView.swift @@ -21,7 +21,8 @@ public var addSizeConstraintsForAspectRatio = true public var shouldNotifyDelegateOnUpdate = true - + public var shouldNotifyDelegateOnDefaultSizeChange = false + // Allows for a view to hardcode which height to use if there is none in the json. var imageWidth: CGFloat? var imageHeight: CGFloat? @@ -228,7 +229,7 @@ let widthWillChange = !MVMCoreGetterUtility.cgfequal(widthConstraint?.constant ?? 0, width ?? 0) let heightWillChange = !MVMCoreGetterUtility.cgfequal(heightConstraint?.constant ?? 0, height ?? 0) - let sizeWillChange = (width == nil || height == nil) && !(size?.equalTo(imageView.image?.size ?? CGSize.zero) ?? false) + let sizeWillChange = shouldNotifyDelegateOnDefaultSizeChange && (width == nil || height == nil) && !(size?.equalTo(imageView.image?.size ?? CGSize.zero) ?? false) let heightChangeFromSpinner = (heightConstraint?.isActive ?? false) ? false : ((height ?? size?.height) ?? 0) < loadingSpinnerHeightConstraint?.constant ?? CGFloat.leastNormalMagnitude return widthWillChange || heightWillChange || sizeWillChange || heightChangeFromSpinner }