From d803ba20e7d384a2f27dd11dfc77eb27fa1c8069 Mon Sep 17 00:00:00 2001 From: Ryan Zhao Date: Mon, 24 Oct 2022 13:56:43 +1100 Subject: [PATCH] themed scrollable subtitle --- .../Views & Modals/ConversationTitleView.swift | 2 -- .../Views & Modals/PagedScrollView.swift | 13 +++++++++---- SessionUIKit/Style Guide/Themes/UIKit+Theme.swift | 12 ++++++++++++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Session/Conversations/Views & Modals/ConversationTitleView.swift b/Session/Conversations/Views & Modals/ConversationTitleView.swift index 4fe5da8df..fef986a5d 100644 --- a/Session/Conversations/Views & Modals/ConversationTitleView.swift +++ b/Session/Conversations/Views & Modals/ConversationTitleView.swift @@ -130,8 +130,6 @@ final class ConversationTitleView: UIView { let diff: CGFloat = (bounds.size.width - oldSize.width) self.stackViewTrailingConstraint.constant = -max(0, diff) self.oldSize = bounds.size - - print("\(bounds.size.width), \(diff)") } public func update( diff --git a/Session/Conversations/Views & Modals/PagedScrollView.swift b/Session/Conversations/Views & Modals/PagedScrollView.swift index ae2af2ad0..12ffdc7e7 100644 --- a/Session/Conversations/Views & Modals/PagedScrollView.swift +++ b/Session/Conversations/Views & Modals/PagedScrollView.swift @@ -3,7 +3,7 @@ import UIKit import SessionUIKit -final class PagedScrollView: UIView { +final class PagedScrollView: UIView, UIScrollViewDelegate { private static let autoScrollingTimeInterval: TimeInterval = 10 private var slides: [UIView] = [] private var slideSize: CGSize = .zero @@ -20,6 +20,7 @@ final class PagedScrollView: UIView { result.isPagingEnabled = true result.showsVerticalScrollIndicator = false result.showsHorizontalScrollIndicator = false + result.delegate = self return result }() @@ -33,8 +34,8 @@ final class PagedScrollView: UIView { private lazy var pageControl: UIPageControl = { let result = UIPageControl(frame: .zero) - result.currentPageIndicatorTintColor = .black - result.pageIndicatorTintColor = .gray + result.themeCurrentPageIndicatorTintColor = .textPrimary + result.themePageIndicatorTintColor = .textSecondary result.themeTintColor = .textPrimary result.set(.height, to: 5) result.transform = CGAffineTransform(scaleX: 0.5, y: 0.5) @@ -111,7 +112,6 @@ final class PagedScrollView: UIView { ), animated: true ) - self.pageControl.currentPage = targetPage } } @@ -119,4 +119,9 @@ final class PagedScrollView: UIView { timer?.invalidate() timer = nil } + + func scrollViewDidScroll(_ scrollView: UIScrollView) { + let pageIndex = round(scrollView.contentOffset.x/slideSize.width) + pageControl.currentPage = Int(pageIndex) + } } diff --git a/SessionUIKit/Style Guide/Themes/UIKit+Theme.swift b/SessionUIKit/Style Guide/Themes/UIKit+Theme.swift index 97916601d..0129482d3 100644 --- a/SessionUIKit/Style Guide/Themes/UIKit+Theme.swift +++ b/SessionUIKit/Style Guide/Themes/UIKit+Theme.swift @@ -452,6 +452,18 @@ public extension UIContextualAction { } } +public extension UIPageControl { + var themeCurrentPageIndicatorTintColor: ThemeValue? { + set { ThemeManager.set(self, keyPath: \.currentPageIndicatorTintColor, to: newValue) } + get { return nil } + } + + var themePageIndicatorTintColor: ThemeValue? { + set { ThemeManager.set(self, keyPath: \.pageIndicatorTintColor, to: newValue) } + get { return nil } + } +} + public extension GradientView { var themeBackgroundGradient: [ThemeValue]? { set {