Skip to content

[Android] pointerEvents + opacity - unstable #21026

@danielgindi

Description

@danielgindi

Environment

  React Native Environment Info:
    System:
      OS: macOS High Sierra 10.13.6
      CPU: x64 Intel(R) Core(TM) i5-5287U CPU @ 2.90GHz
      Memory: 31.40 MB / 8.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 10.9.0 - /usr/local/bin/node
      npm: 6.2.0 - /usr/local/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 11.4, macOS 10.13, tvOS 11.4, watchOS 4.3
    IDEs:
      Android Studio: 3.1 AI-173.4907809
      Xcode: 9.4.1/9F2000 - /usr/bin/xcodebuild
    npmPackages:
      react: ^16.5.0 => 16.5.0
      react-native: ^0.57.0-rc.4 => 0.57.0-rc.4
    npmGlobalPackages:
      react-native-cli: 2.0.

Description

On Android, using pointerEvents='box-only' is unstable in the presence of opacity style.
Specifically, I'm animating a view's opacity, and after animating and reverting to original value - the pointerEvents property is no longer respected.

This is similar to #10216

Reproducible Demo

        <Animated.View 
          style= {
            opacity: this._anims.opacity
          }]}
          pointerEvents={'box-none'}>
          
              Something clickable here

        </Animated.View>

Now animate this._anims.opacity to 0 and back to 1.

More info & workaround

  • When starting with an opacity of 1, the touches pass through.
  • After changing opacity to 0 and back to 1 (whether by animation or by changing state) - touches stop passing through.
  • If I set the view with a backgroundColor: 'transparent' - it works even after setting opacity to 0.

My guess is (a bit of educated guess, because I actually looked at the code), that by setting opacity to 0 React marks the view as something that's meant only for layout, and not for actually viewing things, so it can optimize it out.
And coming back to opacity 1 - the view comes back (I see it in layout inspector) but it is not marked as BOX_ONLY anymore. A backgroundColor of 'transparent' forces it to always be treated like an actual view.
The backgroundColor workaround in my opinion is exposing another bug - which is an optimization bug, not something that affects functionality.
And it is kind of nice to have right now as it allows controlling how react optimizes the view hierarchy. Food for thought: Maybe consider adding a special prop for that?

Edit:

As @kabbi mentioned, there actually is a property for disabling optimization on view.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugPlatform: AndroidAndroid applications.StaleThere has been a lack of activity on this issue and it may be closed soon.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions