Giter VIP home page Giter VIP logo

Comments (2)

levinli303 avatar levinli303 commented on May 20, 2024

Sharing some thoughts here. There are two issues that I'm considering.

  1. 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.

levinli303 avatar levinli303 commented on May 20, 2024
  1. 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:

  1. If on iOS 13+, use the one in UITraitEnvironment (since there might be overrideUserInterfaceStyle in these)
  2. 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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.