Comments (2)
Sharing some thoughts here. There are two issues that I'm considering.
- Is it really necessary to bridge classes that does not call
super.traitCollectionDidChange(_:)
It is in the plan because if we don't bridge that, dmTraitCollectionDidChange(_:)
won't be called when theme changes but now I'm kind of skeptical whether it is necessary.
I disassembled the UIKitCore (Went for the Catalyst one inside Mac (10.15.5) for convenience but there should not be a difference) and were able to find all these classes.
dmTraitCollectionDidChange(_:)
is offered to users who wish to listen to and respond to theme changes in its subclasses on their own. So there are some classes we definitely don't need to bridge like private classes inside UIKit since you cannot subclass it easily. This already shortened the list of classes by 2/3. And there are classes which are not subclasses of UIView/UIViewController, apparently they can also be excluded (for now). The remaining ones are:
UIView subclasses: UIImageView, UILabel, UIDatePicker, UIPickerView
UIViewController subclass: UISplitViewController
My personal experience with UIKit's traitCollectionDidChange(_:)
is that I usually use it in a UIViewController or UIView subclass that manages other view(s), so I can just modify its subviews' properties inside this method when trait collection changes. The four UIView subclasses don't fall into my category as they either don't usually have subviews or they manage subviews inside themselves. I can think of a use case for UIImageView subclass though
class MyImageView: UIImageView {
override func dmTraitCollectionDidChange(_ previousTraitCollection: DMTraitCollection?) {
super.dmTraitCollectionDidChange(previousTraitCollection)
layer.borderColor = /* some code to retrieve a UIColor */.cgColor
}
}
As for UISplitViewController, I'm not really familiar with it, but I think of it as a wrapper of multiple UIViewControllers and does not have any visual element of its own, so maybe not calling .dmTraitCollectionDidChange(_:)
is ok?
also the list subjects to changes since these calls to super.traitCollectionDidChange(_:) are within Apple.
from fluentdarkmodekit.
- We should add
dmTraitCollection
property requirement to DMTraitEnvironment just like UITraitEnvironment
I reflected on how I integrated IOS13's dark mode inside my own app when using traitCollectionDidChange(_:)
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
if self.traitCollection.userInterfaceStyle == .dark {
/* configure the dark appearance */
}
else {
/* configure the light appearance */
}
}
Currently we don't have a self.dmTraitCollection on DMTraitEnvironment. Which means in order to find the current UIView(Controller)'s theme, one should:
- If on iOS 13+, use the one in UITraitEnvironment (since there might be overrideUserInterfaceStyle in these)
- else, use the one in DMTraitCollection.override
Since we are back porting it, we should just provide a self.dmTraitCollection that automatically does it for users.
What are your thoughts on these? @icodesign @zhuorantan @imWildCat @li-bei
from fluentdarkmodekit.
Related Issues (20)
- `dmTraitCollectionDidChange(_ previousTraitCollection: DMTraitCollection?)` not called HOT 2
- Memory HOT 11
- Dark mode in HTML HOT 1
- 'FluentDarkModeKit/FluentDarkModeKit-Swift.h' file not found HOT 5
- iOS12 UIButton HOT 1
- WidgetExtension #error unsupported Swift architecture HOT 8
- Error pod install HOT 4
- Remove git-lfs? HOT 12
- Project does not build once added. HOT 2
- Bundle SwiftLint inside the project? HOT 4
- Does it support layer? HOT 4
- The minimum supported version. HOT 1
- How to use ? HOT 4
- Usability in Objective-C only Projects HOT 1
- Tabbar can not change HOT 2
- Bug:objc_retain + 16 HOT 4
- Namespace style HOT 5
- Sometimes Without UIScence
- Version not released in CocoaPods HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fluentdarkmodekit.