我有这个功能
export function chooseContact(){
ContactsWrapper.getContact().then((contact) => { //opens stock phone address book
var phone = contact['phone']; // retrieves phone number from picked contact
global.phoneDemo = phone; //initializes to the global var in order to access from anywhere
}).catch((error) => { // these line standard
console.log("ERROR CODE: ", error.code);
console.log("ERROR MESSAGE: ", error.message);
});}
在全局变量中成功存储联系人的电话号码后,我在渲染视图方法中使用它
const Home = ({
home
value: {client},
onClientChange,
onSubmit}) => (
<View style={styles.container}>
<InputGroup borderType="underline" style={styles.inputGroup}>
<Icon name="md-contact" style={styles.icon}/>
<Input value={global.phoneDemo?phoneDemo:client}
onChangeText={onClientChange}/>
<Icon name="ios-contacts" style={styles.addressBook} onPress= {chooseContact}/> //this acceesses above function and opens stock contacts on a phone
);
除了将电话号码存储在全局变量中之后,一切都很好我可以在输入上自动设置它,如果我重新导航到另一个组件并再次返回,在这种情况下只有输入自动填充其他方式否。如何在选择联系后自动设置它。