DrawerLayoutAndroid没有显示任何内容?

时间:2016-02-24 10:16:57

标签: 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

可能是什么原因? (也没有任何错误消息,似乎编译得很好。)

1 个答案:

答案 0 :(得分:2)

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