Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug][Android] NativeMethodMixins don't work unless the view has a native property #9382

Closed
hey99xx opened this issue Aug 12, 2016 · 3 comments
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.

Comments

@hey99xx
Copy link

hey99xx commented Aug 12, 2016

NativeMethodMixins don't work unless the view has a native property. As far as I know this bug only happens on Android, I'm testing with a device on Android Marshmallow API 23, according to one of my coworkers the example below has no issue on iOS.

I've brought down my test case to this simple component.

class MyComponent extends React.Component {
    render() {
        return (
            <View ref="myView" style={{opacity:1}}>
                {this.props.children}
            </View>
        );
    }
    componentDidMount() {
        this.refs.myView.measureInWindow((x,y,width,height) => {
            console.log(x,y,width,height)
        });
    }
}

When you render this component, you should see something like 0 0 50 0 in the console while debugging with Chrome. Now if I remove style={{opacity:1}} part, I get undefined undefined undefined undefined in the console. The expected behavior is I should keep getting the same log even when the style prop is removed.

Putting break points in NativeViewHierarchyManager#createView method, it was never invoked with myView when the native property is removed. I check which views are created on the native side by printing with findNodeHandle function.

@chirag04 chirag04 reopened this Aug 13, 2016
@hey99xx hey99xx changed the title NativeMethodMixins don't work unless the view has a native property (Bug - Android) NativeMethodMixins don't work unless the view has a native property Aug 13, 2016
@rmevans9
Copy link
Contributor

@facebook-github-bot label Android

@hey99xx hey99xx changed the title (Bug - Android) NativeMethodMixins don't work unless the view has a native property [Bug][Android] NativeMethodMixins don't work unless the view has a native property Aug 13, 2016
@ghost ghost added Android Ran Commands One of our bots successfully processed a command. labels Aug 13, 2016
@hey99xx
Copy link
Author

hey99xx commented Aug 13, 2016

I suspect NativeViewHierarchyOptimizer would be responsible of this bug. If React detects that myView is simply pass through, it does not create its native view (android.view.ViewGroup), so NativeViewHierarchyManager will not be able to find the actual native views even when they're requested. When I do put a style property, React likely detects that the view needs a native view.
I'm not going to be able to confirm my suspcision until Monday (when I'll be in office). Hopefully an Android engineer ( @mkonicek ?) would see this bug report soon.

Edit: Just noticed https://facebook.github.io/react-native/docs/view.html#collapsable , is that intended for this kind of purposes?

@hey99xx
Copy link
Author

hey99xx commented Sep 21, 2016

Since I've created this bug, I have verified my suspicion that the backing native view was never created. Now I always force it to be created with collapsable property. It's a minor annoyance, but I can live with it.

@hey99xx hey99xx closed this as completed Sep 21, 2016
@facebook facebook locked as resolved and limited conversation to collaborators May 24, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

4 participants