2017-03-11 18 views

답변

3

텍스트 입력에 대한 참조를 추가하고 모달의 onShow 핸들러에서 focus 메소드를 호출 할 수 있습니다.

import React, { Component } from 'react'; 
import { Modal, Text, TextInput, TouchableHighlight, View } from 'react-native'; 

export default class ModalExample extends Component { 

    state = { 
    modalVisible: false, 
    } 

    render() { 
    return (
     <View style={{flex: 1, justifyContent:'center', alignSelf: 'center'}}> 
     <Modal 
      animationType={"slide"} 
      transparent={false} 
      visible={this.state.modalVisible} 
      onShow={() => { this.textInput.focus(); }} 
      > 
     <View style={{backgroundColor: 'green', marginTop: 50, width: 300, padding: 50, alignSelf: 'center'}}> 
      <View> 
      <Text>Hello World!</Text> 
      <TextInput 
       ref={(input) => { this.textInput = input; }} 
       style={{ padding: 20, backgroundColor: 'white', color: 'red' }} 
      /> 
      </View> 
     </View> 
     </Modal> 

     <TouchableHighlight onPress={() => { 
      this.setState({modalVisible: true}); 
     }}> 
      <Text>Show Modal</Text> 
     </TouchableHighlight> 

     </View> 
    ); 
    } 
} 
+0

완벽한! 그게 바로 제가 찾던 것입니다. 고맙습니다! –

관련 문제