mapbox / mapbox-navigation-ios

Turn-by-turn navigation logic and UI in Swift on iOS
https://docs.mapbox.com/ios/navigation/
Other
861 stars 310 forks source link

[Bug]: Unable to customize the Style #3982

Closed ShanMa1991 closed 2 years ago

ShanMa1991 commented 2 years ago

Mapbox Navigation SDK version

v2.6.0-rc.1

Steps to reproduce

  1. In the Example App, create a custom MapboxNavigation.Style as below.
    class NightStyleSpy: NightStyle {
    override func apply() {
        super.apply()
        UILabel.appearance(whenContainedInInstancesOf: [FeedbackViewController.self]).textColor = .red
    }
    }
  2. And replace the styleManager.styles = [DayStyle(), NightStyle()] with styleManager.styles = [DayStyle(), NightStyleSpy()] in ViewController.setupStyleManager()
  3. Choose the night style by choose to Toggle Day/Night Style
  4. Click to see the FeedbackViewController label.

Expected behavior

The label is red in text color expected

Actual behavior

The label shows the default white color. actual

Is this a one-time issue or a repeatable issue?

repeatable

MaximAlien commented 2 years ago

I think that this is expected behavior. Appearance changes for certain trait collections now have precedence over global change, this means that appearance change you've posted in example will not have any effect. Instead, for iOS such styling should be used:

UILabel.appearance(for: UITraitCollection(userInterfaceIdiom: .phone), whenContainedInInstancesOf: [FeedbackViewController.self]).textColor = .red

I've also created this ticket in our examples repo to refresh legacy styling.

ShanMa1991 commented 2 years ago

@MaximAlien Thanks for the information and the example, it works as expected.

jinny-nam commented 2 years ago

hi @MaximAlien and @ShanMa1991, does it mean that the way for customzing style in this example is no longer valid? When testing this example by setting different color to manuevers (e.g. LanesView.appearance().backgroundColor, ManeuverView.appearance().backgroundColor), the code doens't change the color. (testing on the phone simulator, not carplay)

ShanMa1991 commented 2 years ago

@jinny-nam Yes, right now we may need to add UITraitCollection to customize the style as in the comment. We'll update the Example repo for this issue. Thanks!

ShanMa1991 commented 2 years ago

Hi @jinny-nam, https://github.com/mapbox/mapbox-navigation-ios/pull/4086 has been merged to provide a code snippet for custom styling. https://github.com/mapbox/mapbox-navigation-ios-examples/pull/188 will be merged to update the Example for Styled UI Elements. The major change is that now users need to add the UITraitCollection for UIAppearance when customize UI components for styling.