Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Optional style properties treat nil as a function #6095

Closed

Description

@1ec5

On iOS and macOS, properties on MGLStyleLayer classes for optional attributes have somewhat unpredictable nullability. For example, the style specification defines the background-color property as being optional with a default value of #000000. If I create an MGLBackgroundStyleLayer and immediately add it to an MGLStyle, the backgroundColor property is nil rather than the default value of +[UIColor blackColor]:

(lldb) po layer.backgroundColor
 nil

That’s fine; perhaps I could consider the property to be nullable with an implicit default value. But if I set the property to be nil, it ends up as a function with no stops:

(lldb) po layer.backgroundColor = [UIColor redColor]
UIExtendedSRGBColorSpace 1 0 0 1

(lldb) po layer.backgroundColor = nil
 nil

(lldb) po layer.backgroundColor
<MGLStyleAttributeFunction: 0x7fdc23c09e90, base = 0; stops = {
}>

To be sure, setting the property to a non-nil constant value does give the expected result:

(lldb) po layer.backgroundColor = [UIColor redColor]
UIExtendedSRGBColorSpace 1 0 0 1

(lldb) po layer.backgroundColor
UIExtendedSRGBColorSpace 1 0 0 1

The SDK should intercept a stop-less function and return nil instead.

Better yet, mbgl::style::Layer should have a formal concept of a default value so that we can implement the null_resettable semantics in the SDK. That is, an optional property should never return nil (instead returning the default value), but you can set the property to nil in order to revert it to the default value.

/cc @frederoni @jfirebaugh @ivovandongen

Activity

  1. added
    iOS
    macOS
    on Aug 19, 2016
  2. added this to the ios-v3.4.0 milestone on Aug 19, 2016
  3. jfirebaugh commented on Aug 22, 2016

    @jfirebaugh
    Contributor

    Better yet, mbgl::style::Layer should have a formal concept of a default value so that we can implement the null_resettable semantics in the SDK. That is, an optional property should never return nil (instead returning the default value), but you can set the property to nil in order to revert it to the default value.

    With these semantics, how would you distinguish a default-valued property from a property whose value happens to be set to the same value as the default?

  4. 1ec5 commented on Aug 22, 2016

    @1ec5
    ContributorAuthor

    With these semantics, how would you distinguish a default-valued property from a property whose value happens to be set to the same value as the default?

    That’s a good question. Is it important to be able to distinguish between these two cases at the SDK level? If so, then we should keep the properties nullable but fix the issue where the setting to nil creates a no-op function. If not, then null_resettable would allow us to eliminate the concept of an “implicit default”, which is even less common in Objective-C APIs than null_resettable.

  5. jfirebaugh commented on Aug 22, 2016

    @jfirebaugh
    Contributor

    I don't know how important it is at the SDK level, but I think it's a distinction we should preserve at the core level; I don't think we should change the behavior of existing mbgl::style::Layer accessors. Instead we could add methods to obtain property default values.

  6. 1ec5 commented on Aug 22, 2016

    @1ec5
    ContributorAuthor

    Split out #6117 to track accessors for property default values. Meanwhile, this ticket tracks the bug that you can’t get a property back to nil (undefined).

  7. 1ec5 commented on Aug 23, 2016

    @1ec5
    ContributorAuthor

    null_resettable semantics are being tracked in #6126.

  8. modified the milestones: , ios-v3.4.0 on Oct 30, 2016
  9. 1ec5 commented on Dec 1, 2016

    @1ec5
    ContributorAuthor

    Per #7249 (comment), this was the stopless functions were likely an SDK-level issue. The code for converting an mbgl::style::PropertyValue into an MGLStyleValue has been rewritten twice since I reported this issue, and the observed symptoms are long gone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugiOSmacOSruntime styling

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions