How do I render a component when a button is clicked in React Native

Frosty619

I am just starting to learn ReactNative and I cant seem to find the pertinent info on their tutorials page.

I have a list which is rendered on the page, each item in the list has an info button. When the info button is clicked, I want to render a new screen (component) which displays additional information about the item.

items-list.component.js:

render: function() {
        let content;

        if (this.state.dataSource._cachedRowCount > 0) {
            // console.log('data render list')
            content = (<View style={styles.container}>
                            <View style={globalStyles.header}>                     
                                <Text style={globalStyles.headerText}>Calls History</Text>
                                <Icon name="plus" size={24} color="#fff" style={{marginRight: 4}}/>                            
                            </View>

                            <ListView dataSource={this.state.dataSource}
                                      renderRow={this.renderRow}>
                            </ListView>
                        </View>);
        } else {
            content = (<View><LoadingAnimation></LoadingAnimation></View>);
        }
        return (<View style={styles.container}>{content}</View>);
    },


renderRow(rowData) {

                //row contains item name, image displayed here:


                <Image source = {{uri: rowData.peers[0].avatar}}
                       style={globalStyles.avatar} />
               <View style ={styles.container}>       
                    <Text style={styles.nameText} numberOfLines={1}>{rowData.peer}</Text>
                    <Text style={styles.rowText} numberOfLines={1}>{rowData.ts.date}</Text>                     
                </View>      

                 <TouchableHighlight onPress ={() =>  <CallsInfo callsData={rowData}/> }> 
                     <Icon name="information" size={24} color="#9e9e9e" style={styles.rowIcon}/>

                </TouchableHighlight>

calls-info.js:

var React = require('react-native');


var MyButton = React.createClass({
  render() {
    return (
      <View>
        <Text>{this.props.callsData}</Text>
      </View>
    )
  },
});

What I want to do is when the TouchableHighLight is pressed, the user is taken to a new screen with the data passed to it.

I tried to do this on my own by passing CallsInfo, which is a component, to the button, but when I click it, nothing happens.

Thanks!

Smiter

Good article about it.

You need to use navigator object to transition between different scenes in your app.

e.g in your App.js, renderScene can look like this:

renderScene(route) {
  return (
    <View style={[route.style]}>
       <route.Page extras={route.props} />
    </View>
  )
}

And you can attach onPress handler with the following logic

onChangeRoute() {
 this.navigator.push({Page: YourComponent, props: yourprops});
}

So your component will have an access to extras props by using:

this.props.extras in YourComponent

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Not sure how to render this component with click of a button in react-native

From Dev

How do I export Facebook Messenger "Send" Button as a Native UI Component in React Native?

From Dev

Render a component onPress(TouchableOpacity/Button) in React Native

From Dev

How do i target React component which is clicked

From Dev

How do I SAFELY render Markdown from a React component?

From Dev

How do I render Markdown from a React component?

From Dev

How do I render json in my react component?

From Dev

How do I run function in vala asynchronously when a button is clicked

From Java

How do I open phone settings when a button is clicked?

From Dev

How do I change foreground color of a button when clicked?

From Dev

How do I change the text of a button when it is clicked? - Swift

From Dev

c# How do I open the combobox when the button is clicked

From Dev

How do I run function in vala asynchronously when a button is clicked

From Java

How do I change the theme when I press the button? (React-native)

From Dev

How do I render a function which contain a view in react native?

From Dev

How do I render section headers with ListView in react native?

From Dev

How to render component with ajax in react native?

From Dev

React-native Airbnb-Maps: How do I render a button inside the airbnb maps pop-up box?

From Dev

In React Native (and Ignite), how do I create a ListView (inside a tab) that navigates to another container when a list item is clicked?

From Dev

How do I alternate two Images in a react native component

From Dev

How do I add a right button to NavigatorIOS in React Native?

From Dev

How do I add custom title and button to a header in React Native?

From Dev

How do I add a right button to NavigatorIOS in React Native?

From Dev

How can I get when the button is clicked?

From Dev

how do I dynamically render title as component

From Dev

How to apply css with native js when a button is clicked on the page

From Dev

How do I render a list of items into my React Component from mlab?

From Dev

How do I Render a new component in React using Material-UI AppBar onTitleClick Property?

From Dev

How do I know which button is clicked when the bootstrap modal closes?

Related Related

  1. 1

    Not sure how to render this component with click of a button in react-native

  2. 2

    How do I export Facebook Messenger "Send" Button as a Native UI Component in React Native?

  3. 3

    Render a component onPress(TouchableOpacity/Button) in React Native

  4. 4

    How do i target React component which is clicked

  5. 5

    How do I SAFELY render Markdown from a React component?

  6. 6

    How do I render Markdown from a React component?

  7. 7

    How do I render json in my react component?

  8. 8

    How do I run function in vala asynchronously when a button is clicked

  9. 9

    How do I open phone settings when a button is clicked?

  10. 10

    How do I change foreground color of a button when clicked?

  11. 11

    How do I change the text of a button when it is clicked? - Swift

  12. 12

    c# How do I open the combobox when the button is clicked

  13. 13

    How do I run function in vala asynchronously when a button is clicked

  14. 14

    How do I change the theme when I press the button? (React-native)

  15. 15

    How do I render a function which contain a view in react native?

  16. 16

    How do I render section headers with ListView in react native?

  17. 17

    How to render component with ajax in react native?

  18. 18

    React-native Airbnb-Maps: How do I render a button inside the airbnb maps pop-up box?

  19. 19

    In React Native (and Ignite), how do I create a ListView (inside a tab) that navigates to another container when a list item is clicked?

  20. 20

    How do I alternate two Images in a react native component

  21. 21

    How do I add a right button to NavigatorIOS in React Native?

  22. 22

    How do I add custom title and button to a header in React Native?

  23. 23

    How do I add a right button to NavigatorIOS in React Native?

  24. 24

    How can I get when the button is clicked?

  25. 25

    how do I dynamically render title as component

  26. 26

    How to apply css with native js when a button is clicked on the page

  27. 27

    How do I render a list of items into my React Component from mlab?

  28. 28

    How do I Render a new component in React using Material-UI AppBar onTitleClick Property?

  29. 29

    How do I know which button is clicked when the bootstrap modal closes?

HotTag

Archive