【发布时间】:2018-08-04 13:28:55
【问题描述】:
错误:
当我尝试在我的 android 设备上的 snak.expo.io 和 expo 客户端上使用已安装的 radioButton 包时,我收到此错误。我已经在网上搜索了解决方案,但无济于事。
App.js
import React from 'react';
import {
StyleSheet,
Text,
View,
TouchableOpacity,
AppRegistry,
StatusBar,
} from 'react-native';
import { StackNavigator } from 'react-navigation'; // 1.0.0-beta.23
import UCI from './screens/UCI';
class App extends React.Component {
static navigationOptions = {
header: null,
};
render() {
return (
<View style={styles.container}>
<StatusBar hidden={true} />
<View style={styles.boxContainer}>
<View style={[styles.boxContainer, styles.boxOne]}>
<Text style={styles.paragraph}>Adinkra</Text>
</View>
<View style={styles.boxContainerToggle}>
<TouchableOpacity
style={[styles.boxContainer, styles.boxThree]}
onPress={() => this.props.navigation.navigate('UCI')}>
<Text style={styles.paragraph}>BEGIN</Text>
</TouchableOpacity>
</View>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'column',
},
boxContainer: {
flex: 1, // 1:3
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'white',
},
boxContainerToggle: {
flex: 1,
flexDirection: 'row',
padding: 20,
},
boxOne: {
flex: 6, // 5:6
justifyContent: 'space-around',
alignItems: 'center',
},
boxThree: {
flex: 1, // 1:6
flexDirection: 'row',
backgroundColor: 'skyblue',
width: '50%',
height: '100%',
},
paragraph: {
margin: 24,
fontSize: 27,
fontWeight: 'bold',
textAlign: 'center',
color: '#34495e',
},
});
const appScreens = StackNavigator({
Index: { screen: App },
UCI: { screen: UCI },
});
AppRegistry.registerComponent('Adinkra', () => appScreens);
export default appScreens;
UCI.js
import React, { Component } from 'react';
import { View, StyleSheet, TextInput } from 'react-native';
import { RadioGroup, RadioButton } from 'react-radio-buttons'; // 1.2.1
export default class UCI extends Component {
render() {
return (
<View style={styles.container}>
<TextInput
style={{height: 40}}
placeholder="Full Name"
onChangeText={(text) => this.setState({text})}
/>
<RadioGroup onChange={ this.onChange } horizontal>
<RadioButton value="Male">Male</RadioButton>
<RadioButton value="Female">Female</RadioButton>
</RadioGroup>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
alignItems: 'center',
justifyContent: 'center',
},
});
【问题讨论】:
-
React 可视化组件不适用于 react-native,因为常规 html 标签和组件在 react-native 中不存在。更多信息可以找到HERE
-
请阅读Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers? - 总结是这不是解决志愿者的理想方式,并且可能会适得其反。请不要将此添加到您的问题中。
-
第一条评论解释了您收到错误的原因。您基本上只需要使用 React Native 单选按钮库,例如:npmjs.com/package/react-native-simple-radio-button
标签: reactjs react-native radio-button