From 70bc23b09d2c9a47d2204c41f52dc20babeac86a Mon Sep 17 00:00:00 2001 From: Daniil Vinogradov Date: Thu, 19 Dec 2024 02:33:25 +0100 Subject: [PATCH] UILabel fix trait collection update --- Submodules/UIKit/include/UIColor.h | 8 ++++++++ Submodules/UIKit/include/UILabel.h | 3 ++- Submodules/UIKit/lib/UIColor.cpp | 8 -------- Submodules/UIKit/lib/UILabel.cpp | 5 +++++ app/Screens/TestViewController/TestViewController.cpp | 4 ++-- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Submodules/UIKit/include/UIColor.h b/Submodules/UIKit/include/UIColor.h index 4a1c075..88238ab 100644 --- a/Submodules/UIKit/include/UIColor.h +++ b/Submodules/UIKit/include/UIColor.h @@ -8,6 +8,14 @@ namespace NXKit { +#define UIColorThemed(lightColor, darkColor) \ +UIColor([](auto collection) {\ +if (collection->userInterfaceStyle() == UIUserInterfaceStyle::dark) \ + return darkColor; \ +else \ + return lightColor;\ +}) + class UIColor { public: UIColor(); diff --git a/Submodules/UIKit/include/UILabel.h b/Submodules/UIKit/include/UILabel.h index 42f2449..8028dd0 100644 --- a/Submodules/UIKit/include/UILabel.h +++ b/Submodules/UIKit/include/UILabel.h @@ -28,6 +28,7 @@ class UILabel: public UIView { [[nodiscard]] NXFloat fontWeight() const { return _fontWeight; } NXSize sizeThatFits(NXSize size) override; + void traitCollectionDidChange(std::shared_ptr previousTraitCollection) override; private: int _numberOfLines = 1; @@ -35,7 +36,7 @@ class UILabel: public UIView { NXFloat _fontWeight = SkFontStyle::kNormal_Weight; NSTextAlignment _textAlignment = NSTextAlignment::left; std::string _text = "Furthermore, العربية نص جميل. द क्विक ब्राउन फ़ॉक्स jumps over the lazy 🐕."; - UIColor _textColor = UIColor::black; + UIColor _textColor = UIColor::label; sk_sp unicode; std::unique_ptr paragraph; diff --git a/Submodules/UIKit/lib/UIColor.cpp b/Submodules/UIKit/lib/UIColor.cpp index e473265..cb44c4c 100644 --- a/Submodules/UIKit/lib/UIColor.cpp +++ b/Submodules/UIKit/lib/UIColor.cpp @@ -4,14 +4,6 @@ using namespace NXKit; -#define UIColorThemed(lightColor, darkColor) \ -UIColor([](auto collection) {\ -if (collection->userInterfaceStyle() == UIUserInterfaceStyle::dark) \ - return darkColor; \ -else \ - return lightColor;\ -}) - // Transparent UIColor UIColor::clear = UIColor(0, 0, 0, 0); diff --git a/Submodules/UIKit/lib/UILabel.cpp b/Submodules/UIKit/lib/UILabel.cpp index f0e0f86..fa5c577 100644 --- a/Submodules/UIKit/lib/UILabel.cpp +++ b/Submodules/UIKit/lib/UILabel.cpp @@ -48,6 +48,11 @@ NXSize UILabel::sizeThatFits(NXSize size) { return { rWidth, height }; } +void UILabel::traitCollectionDidChange(std::shared_ptr previousTraitCollection) { + UIView::traitCollectionDidChange(previousTraitCollection); + setNeedsLayout(); +} + void UILabel::draw() { updateParagraph(); diff --git a/app/Screens/TestViewController/TestViewController.cpp b/app/Screens/TestViewController/TestViewController.cpp index d24be62..2d9d5ba 100644 --- a/app/Screens/TestViewController/TestViewController.cpp +++ b/app/Screens/TestViewController/TestViewController.cpp @@ -115,7 +115,7 @@ void TestViewController::loadView() { // animateBlur(blur); bottomBar = new_shared(); - bottomBar->setBackgroundColor(UIColor::gray); + bottomBar->setBackgroundColor(UIColor::secondarySystemBackground); rootView->addSubview(bottomBar); label2 = new_shared(); @@ -155,7 +155,7 @@ void TestViewController::loadView() { blur->setFrame({ 80, 200, 240, 240 }); rootView->addSubview(blur); blur->layer()->setCornerRadius(12); - blur->setBackgroundTintColor(0x60DDDDDD); + blur->setBackgroundTintColor(UIColorThemed(UIColor(0x60DDDDDD), UIColor(0x60404040))); blur->addSubview(dragMeViewLabel);