passProps: {
store: ListStore
}
}} />
)
}
}
AppRegistry.registerComponent(‘ReactNativeMobX’, () => ReactNativeMobX)
在入口文件中我们创建了一个基本的导航状态,并导入了新创建的数组存储器。在 initialRoute 中我们传入数据存储作为属性。我们还把已经创建的组件 App 作为初始路由。App 将会访问属性中的数据存储。
在 configureScene 中,我们检查类型(type)是否是 ‘Modal’,是则返回 floatFromBottom 这个场景配置项,可以把下一个场景也设置为模态的。
现在,我们来创建应用组件。这确是一个大型的组件,还有很多需要完善的地方,但我们创建了一个允许增加和删除列表条目的基本用户界面。调用数据存储的方法来和我们的应用状态交互。app/App.js 的内容:
import React, { Component } from ‘react’
import { View, Text, TextInput, TouchableHighlight, StyleSheet } from ‘react-native’
import {observer} from ‘mobx-react/native’
import NewItem from ‘./NewItem’
@observer
class TodoList extends Component {
constructor () {
super()
this.state = {
text: ‘’,
showInput: false
}
}
toggleInput () {
this.setState({ showInput: !this.state.showInput })
}
addListItem () {
this.props.store.addListItem(this.state.text)
this.setState({
text: ‘’,
showInput: !this.state.showInput
})
}
removeListItem (item) {
this.props.store.removeListItem(item) 《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题&#