对android的AlertIOS.prompt作出本机替代反应?
我正在学习react native的教程,不过他们是在IOS上学习的,有一部分他们是这样使用AlertIOS.prompt的对android的AlertIOS.prompt作出本机替代反应?,android,react-native,Android,React Native,我正在学习react native的教程,不过他们是在IOS上学习的,有一部分他们是这样使用AlertIOS.prompt的 AlertIOS.prompt( 'Add New Item', null, [ {text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'}, { text: 'Add', onPress: (text) =>
AlertIOS.prompt(
'Add New Item',
null,
[
{text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'},
{
text: 'Add',
onPress: (text) => {
this.itemsRef.push({ title: text })
}
},
],
'plain-text'
);
我试图为android重新制作这个,但无法让它工作,我确实找到了这个
从“反应本机提示”导入提示;
这是我的国家({
提示:错误,
信息:“你取消了”
}) }
onSubmit={(值)=>this.setState({
提示:错误,
信息:`你说的是“${value}”`
}) }/>
然而,我也不能让它工作,它应该在我按下按钮时显示提示,但什么也没有发生
以下是AlertIOS的完整原始代码
'use strict';
import React, {Component} from 'react';
import ReactNative from 'react-native';
const firebase = require('firebase');
const StatusBar = require('./components/StatusBar');
const ActionButton = require('./components/ActionButton');
const ListItem = require('./components/ListItem');
const styles = require('./styles.js')
const {
AppRegistry,
ListView,
StyleSheet,
Text,
View,
TouchableHighlight,
AlertIOS,
} = ReactNative;
// Initialize Firebase
const firebaseConfig = {
apiKey: "AIzaSyA9y6Kv10CAl-QOnSkMehOyCUejwvKZ91E",
authDomain: "dontforget.firebaseapp.com",
databaseURL: "https://dontforget-bd066.firebaseio.com",
storageBucket: "dontforget-bd066.appspot.com",
};
const firebaseApp = firebase.initializeApp(firebaseConfig);
class dontforget extends Component {
constructor(props) {
super(props);
this.state = {
dataSource: new ListView.DataSource({
rowHasChanged: (row1, row2) => row1 !== row2,
})
};
this.itemsRef = this.getRef().child('items');
}
getRef() {
return firebaseApp.database().ref();
}
listenForItems(itemsRef) {
itemsRef.on('value', (snap) => {
// get children as an array
var items = [];
snap.forEach((child) => {
items.push({
title: child.val().title,
_key: child.key
});
});
this.setState({
dataSource: this.state.dataSource.cloneWithRows(items)
});
});
}
componentDidMount() {
this.listenForItems(this.itemsRef);
}
render() {
return (
<View style={styles.container}>
<StatusBar title="Grocery List" />
<ListView
dataSource={this.state.dataSource}
renderRow={this._renderItem.bind(this)}
enableEmptySections={true}
style={styles.listview}/>
<ActionButton onPress={this._addItem.bind(this)} title="Add" />
</View>
)
}
_addItem() {
AlertIOS.prompt(
'Add New Item',
null,
[
{text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'},
{
text: 'Add',
onPress: (text) => {
this.itemsRef.push({ title: text })
}
},
],
'plain-text'
);
}
_renderItem(item) {
const onPress = () => {
AlertIOS.alert(
'Complete',
null,
[
{text: 'Complete', onPress: (text) => this.itemsRef.child(item._key).remove()},
{text: 'Cancel', onPress: (text) => console.log('Cancelled')}
]
);
};
return (
<ListItem item={item} onPress={onPress} />
);
}
}
AppRegistry.registerComponent('dontforget', () => dontforget);
“严格使用”;
从“React”导入React,{Component};
从“react native”导入ReactNative;
const firebase=require('firebase');
const StatusBar=require('./组件/StatusBar');
const ActionButton=require('./组件/ActionButton');
const ListItem=require('./组件/ListItem');
const styles=require('./styles.js')
常数{
评估学,
ListView,
样式表,
文本,
看法
触控高光,
AlertIOS,
}=反应性;
//初始化Firebase
常量firebaseConfig={
apiKey:“AIzaSyA9y6Kv10CAl-QOnSkMehOyCUejwvKZ91E”,
authDomain:“dontforget.firebaseapp.com”,
数据库URL:“https://dontforget-bd066.firebaseio.com",
storageBucket:“dontforget-bd066.appspot.com”,
};
const firebaseApp=firebase.initializeApp(firebaseConfig);
类dontforget扩展组件{
建造师(道具){
超级(道具);
此.state={
数据源:新建ListView.dataSource({
行已更改:(行1,行2)=>行1!==行2,
})
};
this.itemsRef=this.getRef().child('items');
}
getRef(){
返回firebaseApp.database().ref();
}
listenformes(itemsRef){
itemsRef.on('值',(捕捉)=>{
//将子对象作为数组获取
var项目=[];
snap.forEach((子项)=>{
推({
标题:child.val().title,
_关键字:child.key
});
});
这是我的国家({
dataSource:this.state.dataSource.cloneWithRows(项目)
});
});
}
componentDidMount(){
this.listenforms(this.itemsRef);
}
render(){
返回(
)
}
_附加项(){
AlertIOS.prompt(
“添加新项目”,
无效的
[
{text:'Cancel',onPress:()=>console.log('Cancel Pressed'),样式:'Cancel'},
{
文本:“添加”,
onPress:(文本)=>{
this.itemsRef.push({title:text})
}
},
],
“纯文本”
);
}
_renderItem(项目){
const onPress=()=>{
警报(
"完成",,
无效的
[
{text:'Complete',onPress:(text)=>this.itemsRef.child(item.\u key).remove(),
{text:'Cancel',onPress:(text)=>console.log('Cancelled')}
]
);
};
返回(
);
}
}
AppRegistry.registerComponent('dontforget',()=>dontforget);
有谁能告诉我,我怎样才能在android上实现这一点吗?这看起来是一个很好的选择,因为它是本机实现的
实际上,您可以使用在Android和Ios上都能正常工作的跨平台提示组件。链接如下所示 及其 存储库 链接是
我认为您可以使用以下库: 获取用户输入的示例代码如下(不在文档中)
帐户删除
是否要删除此帐户?无法撤消此操作。
this.setState({username:text})}/>
{
console.log(this.state.username);
this.setState({promptUser:false});
}} />
我开发了一个小型实用程序来解决这个问题。这可能有用
试试看。它提供本地外观和更多定制选项请为任何链接添加上下文,以便您的答案是独立的,这意味着答案需要在答案本身中。看见如果你能回答如何使用它的问题,那就更好了。展示它如何回答问题
'use strict';
import React, {Component} from 'react';
import ReactNative from 'react-native';
const firebase = require('firebase');
const StatusBar = require('./components/StatusBar');
const ActionButton = require('./components/ActionButton');
const ListItem = require('./components/ListItem');
const styles = require('./styles.js')
const {
AppRegistry,
ListView,
StyleSheet,
Text,
View,
TouchableHighlight,
AlertIOS,
} = ReactNative;
// Initialize Firebase
const firebaseConfig = {
apiKey: "AIzaSyA9y6Kv10CAl-QOnSkMehOyCUejwvKZ91E",
authDomain: "dontforget.firebaseapp.com",
databaseURL: "https://dontforget-bd066.firebaseio.com",
storageBucket: "dontforget-bd066.appspot.com",
};
const firebaseApp = firebase.initializeApp(firebaseConfig);
class dontforget extends Component {
constructor(props) {
super(props);
this.state = {
dataSource: new ListView.DataSource({
rowHasChanged: (row1, row2) => row1 !== row2,
})
};
this.itemsRef = this.getRef().child('items');
}
getRef() {
return firebaseApp.database().ref();
}
listenForItems(itemsRef) {
itemsRef.on('value', (snap) => {
// get children as an array
var items = [];
snap.forEach((child) => {
items.push({
title: child.val().title,
_key: child.key
});
});
this.setState({
dataSource: this.state.dataSource.cloneWithRows(items)
});
});
}
componentDidMount() {
this.listenForItems(this.itemsRef);
}
render() {
return (
<View style={styles.container}>
<StatusBar title="Grocery List" />
<ListView
dataSource={this.state.dataSource}
renderRow={this._renderItem.bind(this)}
enableEmptySections={true}
style={styles.listview}/>
<ActionButton onPress={this._addItem.bind(this)} title="Add" />
</View>
)
}
_addItem() {
AlertIOS.prompt(
'Add New Item',
null,
[
{text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'},
{
text: 'Add',
onPress: (text) => {
this.itemsRef.push({ title: text })
}
},
],
'plain-text'
);
}
_renderItem(item) {
const onPress = () => {
AlertIOS.alert(
'Complete',
null,
[
{text: 'Complete', onPress: (text) => this.itemsRef.child(item._key).remove()},
{text: 'Cancel', onPress: (text) => console.log('Cancelled')}
]
);
};
return (
<ListItem item={item} onPress={onPress} />
);
}
}
AppRegistry.registerComponent('dontforget', () => dontforget);
<Dialog.Container visible={true}>
<Dialog.Title>Account delete</Dialog.Title>
<Dialog.Description>
Do you want to delete this account? You cannot undo this action.
</Dialog.Description>
<Dialog.Input label="Cancel" onChangeText={(text) => this.setState({username : text})} />
<Dialog.Button label="Delete" onPress={() => {
console.log(this.state.username);
this.setState({promptUser : false});
}} />
</Dialog.Container>