react本机导航器视图不呈现
react native navigator view does not render
我正在使用react native制作一个简单的iOS应用程序,导航器出现了一些问题下面是我的代码:
'use strict';
var Dimensions = require('Dimensions');
import React, {
Component,
StyleSheet,
MapView,
Text,
View,
Animated,
Navigator,
TouchableHighlight,
TouchableOpacity,
Image,
PropTypes,
Modal
} from 'react-native';
var {
height: deviceHeight,
width: deviceWidth
} = Dimensions.get('window');
var BasicConfig = Navigator.SceneConfigs.FloatFromLeft;
var CustomLeftToRightGesture = Object.assign({}, BasicConfig.gestures.pop, {
snapVelocity:8,
edgeHitWidth: deviceWidth,
});
var CustomSceneConfig = Object.assign({}, BasicConfig, {
springTension: 100,
springFriction: 1,
gestures:{
pop:CustomLeftToRightGesture,
}
});
var MainMap = React.createClass({
watchID: (null: ?number),
getInitialState: function() {
return {
latitude: 0,
longitude: 0,
initialPosition: 'unknown',
lastPosition: 'unknown',
};
},
openMenu(){
this.props.navigator.push({id: 2,});
},
render: function(){
console.log("123456")
return (
<View style = {styles.container}>
<View style = {styles.TopBarContainer}>
<TouchableOpacity style={styles.toolbarButton}
onPress={this.openMenu}>
<Text style={styles.toolbarButtonText}>{"MENU"}</Text>
</TouchableOpacity>
<Text style={styles.toolbarTitle}>{"Simply Park"}</Text>
<TouchableOpacity style={styles.toolbarButton}
onPress={this.openSeacrh}>
<Image source={require('image!search')} style={styles.toolbarSeacrhImage}/>
</TouchableOpacity>
</View>
<MapView
style={styles.map}
showsUserLocation={true}
followUserLocation={true}
/>
</View>
);
}
});
var ControlPanel = React.createClass({
_handlePress(){
this.props.navigator.pop();
},
render: function() {
console.log("paaaaaaaaanel")
return (
<View style={styles.container}>
<Text style={styles.controlText}>{"Control Panel"}</Text>
<TouchableOpacity style={styles.button} onPress={this._handlePress}>
<Text>{"Close Drawer"}</Text>
</TouchableOpacity>
</View>
)
}
});
var Main = React.createClass({
_renderScene(route, navigator){
if (route.id === 2){
console.log("id is 2");
return <ControlPanel navigator={navigator} />
}else{
console.log("id is 1");
return <MainMap navigator={navigator} />
}
},
_configureScene(route){
return CustomSceneConfig;
},
render(){
console.log("hihihihihihi");
return(
<Navigator
initialRoute={{
id: 1,
}}
renderScene = {this._renderScene}
configureScene = {this._configureScene}
/>
);
}
});
const styles = StyleSheet.create({
container: {
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
justifyContent: 'flex-end',
alignItems: 'center',
},
TopBarContainer:{
position: 'absolute',
backgroundColor: '#3b5998',
top: 0,
left: 0,
right: 0,
bottom: 580,
flexDirection:'row'
},
toolbarButton:{
paddingTop:35,
paddingLeft: 7,
width: 50,
alignItems:'center'
},
toolbarButtonText:{
paddingTop: 5,
color:'#fff',
fontWeight: 'normal',
fontSize: 13,
},
toolbarTitle:{
paddingTop:35,
color:'#fff',
textAlign:'center',
fontWeight:'bold',
fontSize: 18,
flex:1,
},
toolbarSeacrhImage:{
paddingTop: 20,
width: 18,
height:18,
},
map: {
position: 'absolute',
top: 70,
left: 0,
right: 0,
bottom: 0,
},
controlText: {
color: 'white',
},
button: {
backgroundColor: 'white',
borderWidth: 1,
borderColor: 'black',
padding: 10,
bottom: 500,
},
});
module.exports = Main;
我将console.log()用于调试。调试文本在调试xcode dubug控制台上正确显示,但MainMap视图不会显示。我想知道这是否是我的观点风格的问题,但几次尝试后都没有线索。
我的问题的答案是,我正在使用模态在前一个场景到该场景之间转换,并从渲染该视图的前一个视图中删除justifyContent:"flex end",alignItems:"center"
尝试将style={{flex: 1}}
添加到导航器中。
<Navigator
style={{ flex: 1 }}
initialRoute={{
id: 1,
}}
renderScene = {this._renderScene}
configureScene = {this._configureScene}
/>
相关文章:
- '图片'没有用于本机道具的propType'RCTImageView.overlayColor&
- 在iOS和Android上使用React native时,我还能使用本机第三方lirbraries吗
- javascript函数访问ios本机功能
- 如何在从客户端接收数据时从本机方法触发javascript函数?
- 在浏览器中检测本机或第三方PDF插件
- 在视图中渲染多个按钮以编程方式进行本机反应
- react本机导航器视图不呈现
- 反应本机视图渲染
- 将本地 Web 应用包含在 react 本机 Web 视图中
- 是否可以在我现有的网络视图中通过 Javascript 打开一个新的本机网络浏览器
- 键盘关闭模式为交互式时的动画视图高度 [反应本机]
- Android Web 视图中的非本机滚动条性能
- 反应本机列表视图键
- 从列表视图传递 React 本机状态
- 以JavaScript中的反应本机视图为目标
- 使用Cordova Webview/Phonegap按钮onclick(eventlistener)更改本机视图
- 如何增加列表视图行滑动的“反应本机滑动”上的按钮宽度(React Native)
- 可触摸视图响应本机响应速度不是很好
- 反应本机列表视图可触摸突出显示
- Angular 2 本机视图封装