react-navigation - navigating from child component

后端 未结 4 732
面向向阳花
面向向阳花 2020-12-16 01:12

I have a leaderboard which calls a component and passes it data to it like so:

   _renderItem =({item}) => (
    

        
4条回答
  •  被撕碎了的回忆
    2020-12-16 01:59

    This is a 3 page example that shows how to pass the navigate function to a child component and how to customize props send to screens from within the StackNavigator

    // subcomponent ... receives navigate from parent
    const Child = (props) => {
        return (
             props.navigate(props.destination) }>
                {props.text}>>>
            
        );
    }
    // receives navigation from StackNavigator
    const PageOne = (props) => {
        return (
            
                Page One
                
            
        )
    }
    // receives custom props AND navigate inside StackNavigator 
    const PageTwo = (props) => (
        
            {props.text}
            
        
    );
    // receives ONLY custom props (no nav sent) inside StackNAvigator
    const PageThree = (props) => {props.text}
    
    export default App = StackNavigator({
        pageone: { 
            screen: PageOne, navigationOptions: { title: "One" } },
        pagetwo: { 
            screen: (navigation) => , 
            navigationOptions: { title: "Two" } 
        },
        pagethree: { 
            screen: () => , 
            navigationOptions: { title: "Three" }
        },
    });
    

提交回复
热议问题