react-native icon indicating copy to clipboard operation
react-native copied to clipboard

DrawerLayoutAndroid:- undefined is not an object (evaluating DrawerLayoutAndroid.positions )

Open kishanj918 opened this issue 11 years ago • 15 comments

I am using DrawerLayoutAndroid's example code.. Some how it's giving me above mentioned error...

var React = require('react-native');
var {
        AppRegistry,
        Text,
        DrawerLayoutAndroid,
        }= React

var AwesomeProject = React.createClass({
    render: function () {
        var navigationView = (
            <Text style = {{margin: 10, fontSize: 15, textAlign: 'left'}}>I'm in the Drawer!</Text> );
        return (<DrawerLayoutAndroid drawerWidth = {300} drawerPosition = {DrawerLayoutAndroid.positions.Left}
                                     renderNavigationView = {() => navigationView}> <Text
            style = {{margin: 10, fontSize: 15, textAlign: 'right'}}>Hello</Text> <Text
            style = {{margin: 10, fontSize: 15, textAlign: 'right'}}>World!</Text> </DrawerLayoutAndroid> );
    },
});
AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject);

kishanj918 avatar Sep 25 '15 12:09 kishanj918

Try using DrawerLayoutAndroid = require('DrawerLayoutAndroid'); Most Android modules have to be imported this way. I'm not sure why

NishanthShankar avatar Sep 25 '15 13:09 NishanthShankar

@NishanthShankar Thanks. That worked!

kishanj918 avatar Sep 25 '15 13:09 kishanj918

You shouldn't use var DrawerLayoutAndroid = require('DrawerLayoutAndroid'); because that is an unsupported side-effect of how the packager works. See #1821

If you can't use DrawerLayoutAndroid like any other React Native component then that is a bug.

brentvatne avatar Sep 25 '15 16:09 brentvatne

Confirmed that this is not happening: https://rnplay.org/apps/XDP9Tg

Please make sure you're using DrawerLayoutAndroid correctly :)

brentvatne avatar Sep 25 '15 16:09 brentvatne

Oh.. But the examples use it as var AndoridComponent = require(AndoridComponent)

https://github.com/facebook/react-native/blob/master/Examples/UIExplorer/ToolbarAndroidExample.android.js

https://github.com/facebook/react-native/blob/master/Examples/UIExplorer/ProgressBarAndroidExample.android.js

NishanthShankar avatar Sep 25 '15 17:09 NishanthShankar

Encountering the same issues. Only var DrawerLayoutAndroid = require('DrawerLayoutAndroid'); works.

chourobin avatar Sep 25 '15 19:09 chourobin

@NishanthShankar - those are inside of the repo itself, that's a little bit confusing indeed.. Notice that throughout all of the codebase require('X') rather than require('../SomeDirectory/X') are used - this is because of how Facebook uses @providesModule internally.

@chourobin - if you copy the exact code from the above rnplay link I provided and run that locally, do you also get errors?

brentvatne avatar Sep 25 '15 19:09 brentvatne

@brentvatne sorry I spoke too soon, I do run into issues with the copy pasted code in a fresh project.

chourobin avatar Sep 25 '15 20:09 chourobin

@chourobin - with the exact code from the example? That's weird! Can you upload a repo with it and include the node_modules directory too? Thanks!

brentvatne avatar Sep 25 '15 21:09 brentvatne

@brentvatne - Hey Brent, sure here it is: https://github.com/chourobin/AndroidDrawer. Fresh project, copy pasted code & renamed SampleApp -> AndroidDrawer. Unfortunately it only works when I explicitly include 'DrawerLayoutAndroid'.

chourobin avatar Sep 26 '15 22:09 chourobin

Also having this issue from AwesomeProject, only works if drawer is required.

Tjorriemorrie avatar Sep 27 '15 15:09 Tjorriemorrie

I can't duplicate it on that playground but I'm not sure if I'm seeing it either. Maybe this is a version issue. Used default nexus5 device config.

CPU/ABI: Intel Atom (x86)
Target: Android 6.0 (API level 23)
screen shot 2015-09-27 at 20 44 34

@brentvatne What information do you need?

Tjorriemorrie avatar Sep 27 '15 18:09 Tjorriemorrie

Yes, it works if I revert back to 0.11.0. Don't you use deployment tests?

Tjorriemorrie avatar Sep 28 '15 09:09 Tjorriemorrie

Android is currently not tested in the open-source repo.

ide avatar Sep 28 '15 10:09 ide

Android is tested now, this should work!

brentvatne avatar Jan 03 '16 04:01 brentvatne