Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modal View in React Native

Tags:

react-native

I am new to react native, I am trying to present a view modally. I have a table view and when one of the rows is clicked I want the view to show up modally.

This is how I am implementing the transition right now :

renderbooks(books) {
     return (
          <TouchableHighlight onPress={() => this.showbooksDetail(books)}  underlayColor='#dddddd'>
              <View>
                  <View style={styles.container}>

                      <View style={styles.rightContainer}>
                          <Text style={styles.title}>{books.title}</Text>



                          </View>
                  </View>
                  <View style={styles.separator} />
              </View>
          </TouchableHighlight>
     );
 }
 showbooksDetail(books){
   this.props.navigator.push({
     title:books.title,
     component: ProductView,
     passProps:{books}
   });
 }

How can I modify this so that the view can be presented modally?

FYI: I have already looked at multiple questions and sample projects such as these:

  • How do I create a native looking modal view segue with react-native?
  • http://facebook.github.io/react-native/docs/modal.html#content
  • https://github.com/aaronksaunders/React-Modal-Nav-Example
like image 720
L887 Avatar asked Sep 17 '15 13:09

L887


People also ask

How do I create a modal view in react-native?

In your components folder, create a file called Modal. tsx and add the following code: import React from "react"; import { StyleSheet, View, Text, Button } from "react-native"; import RNModal from "react-native-modal"; type ModalProps = { isVisible: boolean; children: React.

What does modal do in react-native?

The React Native Modal is a type of View component which is used to present the content above an enclosing view. There are three different types of options (slide, fade and none) available in a modal that decides how the modal will show inside the react native app.

How do I use popup in react-native?

React Native Popup Dialog We will use PopupDialog component provided by react-native-popup-dialog to make a Dialog. We can use Alert instead of the popup dialog if we just want to show the text but when it comes to the customization of alert content we have to use popup dialog.

How do I open the modal from the bottom in react-native?

import React from 'react'; import { StyleSheet, Text, View, ScrollView, TouchableOpacity, TextInput, Image, Modal, } from 'react-native'; export default class Test extends React. Component { constructor(props) { super(props); this. state = { modalVisible: false, }; } setModalVisible(visible) { this.


1 Answers

Check out the built-in Modal. It's implemented on iOS, Android implementation should come in one of the next releases of React Native.

The documentation contains an example on how to use it.

In your case it would be something like:

renderBooks(books) {
   ...
   <Modal
      animated={true}
      transparent={true}
      visible={!!this.state.selectedBook}>
      <Text>{this.state.selectedBook.title}</Text>
   </Modal>

   ...
}

showDetail(book) {
    this.setState({
        selectedBook: book,
    });
}
like image 194
Martin Konicek Avatar answered Sep 30 '22 14:09

Martin Konicek