私のアプリのメインナビゲーションにreact-native-router-fluxを使用しています。ネストされたルータをセットアップする必要があります。私は地方のリストとサイドバーを持っているマップコンポーネントがあります。行をクリックすると、そのテリトリーに属する細分リストを持つビューに切り替える必要があります。私はいくつかの例を見て、それを理解しようとしました。現在、コンソールにエラーはありませんが、サイドバーには何も表示されません。これを行うより良い方法がある場合は、私に知らせてください。ありがとう!ネストルーティングと反応ネイティブの使い方
Maprouter
export default class RootRouter extends Component {
render() {
return(
<Router hideNavBar={true}>
<Schema name="default" sceneConfig={Navigator.SceneConfigs.FloatFromRight}/>
<Route name="mapSurveyTerritories" wrapRouter={false} component={MapSurveyTerritories} initial={true}/>
<Route name="mapSubdivisions" wrapRouter={false} component={MapSubdivisions} />
</Router>
);
}
}
Map Component
BackAndroid.addEventListener('hardwareBackPress', function() {
Actions.pop();
return true;
});
export default class Map extends Component {
constructor(props) {
super(props);
this.state = {
region: Albuquerque,
};
}
render() {
const { region, markers,surveyTerritories,selectedMarket } = this.state;
return (
<View style={styles.container}>
<Navbar
title="Map"/>
<View style={styles.innerContainer}>
<MapView
style={styles.map}
initialRegion={region}
onLongPress={this.onPress.bind(this)}>
{markers.map(marker => (
<MapView.Marker
ref="m1"
key={marker.id}
coordinate={marker.coordinate}
title={marker.name}>
</MapView.Marker>
))}
</MapView>
<ScrollView style={styles.sidebarContainer}>
<MapRouter />
</ScrollView>
</View>
</View>
);
}
};
module.exports = Map;
領土
class MapSurveyTerritories extends Component {
constructor(props) {
super(props);
var ds = new ListView.DataSource({
rowHasChanged: (r1, r2) => r1 != r2
});
this.state = {
dataSource: ds,
showProgress: true
};
}
componentDidMount() {
this.fetchTerritories();
}
fetchTerritories() {
this.setState({
dataSource: this.state.dataSource
.cloneWithRows(territoriesAlbuquerque),
showSpinner: false
});
}
renderRow(rowData) {
return (
<TouchableHighlight
onPress={()=>Actions.mapSubdivisions({selectedTerritory:rowData})}
underlayColor='#ddd'>
<View style={styles.row}>
<View style={{paddingLeft: 20}}>
<Text>
<Text style={{ fontWeight: '600' }}> {rowData.properties.name} </Text>
</Text>
</View>
</View>
</TouchableHighlight>
);
}
render() {
return (
<View style={{flex: 1,justifyContent: 'flex-start'}}>
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderRow.bind(this)}/>
</View>
);
}
}
module.exports = MapSurveyTerritories;
下位区分
class MapSubdivisions extends Component {
constructor(props) {
super(props);
var ds = new ListView.DataSource({
rowHasChanged: (r1, r2) => r1 != r2
});
this.state = {
dataSource: ds
};
}
componentDidMount() {
this.fetchSubdivisions();
}
fetchSubdivisions() {
console.log('fetchSubdivisions', this.props.selectedTerritory);
this.setState({
dataSource: this.state.dataSource
.cloneWithRows(subdivisionsAlbuquerque),
showSpinner: false
});
}
renderRow(rowData) {
return (
<TouchableHighlight
onPress={()=>Actions.mapSubdivisionDetail({selectedSubdivision:rowData})}
underlayColor='#ddd'>
<View style={styles.row}>
<View style={{paddingLeft: 20}}>
<Text>
<Text style={{ fontWeight: '600' }}> {rowData.properties.name} </Text>
</Text>
</View>
</View>
</TouchableHighlight>
);
}
render() {
return (
<View style={{flex: 1,justifyContent: 'flex-start'}}>
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderRow.bind(this)}/>
</View>
);
}
}
module.exports = MapSubdivisions;
今夜試してみましょう。だから私はsthisマップコンポーネントです。 Navigator Elementを置き換えて、 に戻します。これは、リストを正しくロードするためです。そして、私はMainListViewとDetailViewの間でナビゲーションの小道具を実装するのだろうか?私はアンギュラな背景から来ているので、入れ子になったビューにui-routerを使用することに慣れています。私の質問は、DetailViewがどのようにレンダリングするかを知っていますか? –
texas697
心配はいりません。はい、NavListをDetailListのMainListViewを介して小道具として渡す必要があります。 –
MainListViewで投稿を更新しました。私が何をする必要があるかを私に見せてもらえますか?どのように働く必要があるか、あなたが言っていることを理解しています。 – texas697