javascript - DrawerLayoutAndroid 没有显示任何内容?

标签 javascript react-native

我正在尝试显示 React Native 的 [DrawerLayoutAndroid][1] 组件:

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 */
'use strict'
import React, {
  AppRegistry,
  Component,
  StyleSheet,
  Text,
  TextInput,
  View,
  ScrollView,
  DrawerLayoutAndroid
} from 'react-native'

class Dictionary extends Component {
  constructor(props) {
    super(props)
    this.state = {
      movies: 'Test'
    }
  }

  render() {
    const navigationView = (
    <View style={{flex: 1, backgroundColor: '#fff'}}>
      <Text style={{margin: 10, fontSize: 15, textAlign: 'left'}}>Im in the Drawer!</Text>
    </View>
    )
    return (
      <ScrollView>
        <DrawerLayoutAndroid
          drawerWidth={300}
          drawerPosition={DrawerLayoutAndroid.positions.Left}
          renderNavigationView={() => navigationView}>
          <View style={{flex: 1, alignItems: 'center'}}>
            <Text style={{margin: 10, fontSize: 15, textAlign: 'right'}}>Hello</Text>
            <Text style={{margin: 10, fontSize: 15, textAlign: 'right'}}>World!</Text>
          </View>
        </DrawerLayoutAndroid>
        <View style={styles.parent}>
          <Text>
            Type something in English:
          </Text>

          <TextInput/>

          <Text style={styles.germanLabel}>
            Movies: { this.state.movies }
          </Text>
        </View>
      </ScrollView>
    )
  }
}

const styles = StyleSheet.create({
   parent: {
     padding: 16
   },
   germanLabel: {
     marginTop: 20,
     fontWeight: 'bold'
   },
   germanWord: {
     marginTop: 15,
     fontSize: 30,
     fontStyle: 'italic'
   }
})

AppRegistry.registerComponent('Dictionary', () => Dictionary)

但是,应用程序不显示任何内容:

enter image description here

可能是什么原因? (也没有任何错误消息,看起来一切都编译得很好。)

最佳答案

尝试让你的DrawerLayoutAndroid作为根节点。文档中没有关于此的信息,但对我有帮助。这对您有帮助吗?

关于javascript - DrawerLayoutAndroid 没有显示任何内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35599241/

相关文章:

react-native - 如何检查 React Native 组件何时完成重新渲染?

java - 不允许解析依赖配置 'implementation',因为它被定义为 'canBeResolved=false'

ios - React-Native 调试工具/开发人员菜单在 iOS 设备上不起作用

javascript - 当我们按下 BACKSPACE/DEL/do CUT 时,IE9 中的 oninput 不会触发

javascript - Angular 7/1.x 混合应用程序可以支持 HMR 吗?

javascript - 获取忽略空格的javascript字符串中的最后一个字符

在 Jest 测试中,react-native-reanimated useSharedValue 不会更新

javascript - 使用 react-native-router-flux 将数据从屏幕发送到 Tab 屏幕

javascript - 未捕获的语法错误 : Unexpected token }

javascript - Highcharts 系列图以 tick 开始和结束并以 max 结束