W
W
warchant2016-01-05 23:16:46
React
warchant, 2016-01-05 23:16:46

React Native, how do components "communicate"?

There are three components, DrawerLayoutAndroid, DrawerNav, MainView (DrawerLayoutAndroid contains the rest inside).
There is an event handler onDrawerClose. How can I change some properties or the state of the DrawerNav and MainView components inside this handler?

(
            <DrawerLayoutAndroid
                drawerWidth={300}
                drawerPosition={DrawerLayoutAndroid.positions.Left}
                renderNavigationView={()=> (<DrawerNav />)}
                onDrawerClose={function(){
                    // ???????
                }}
            >
                <MainView />
            </DrawerLayoutAndroid>
        )

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Antropov, 2016-01-06
@warchant

You need to set the state in the handler, and then set it in the renderer.

(
        <DrawerLayoutAndroid
            drawerWidth={300}
            drawerPosition={DrawerLayoutAndroid.positions.Left}
            renderNavigationView={()=> (<DrawerNav open={this.state.navOpen} />)}
            onDrawerClose={() => this.setState({navOpen: true})}
         >
            <MainView />
        </DrawerLayoutAndroid>
    )

To simplify, I left the handler in place, but for optimization it would be better to put it in a class method.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question