#react-native
#реагирующая встроенная
Вопрос:
Я создаю приложение, основанное на react. По сути, у него есть BottomTabNavigation для навигации по экранам.
На одном из моих экранов я хочу открыть другой экран с помощью BottomTabNavigation, чтобы перейти к другим экранам внутри.
К сожалению, я ничего не нашел в Google или в функции поиска. Возможно ли это создать?
Ответ №1:
Вы можете сделать это легко с помощью модуля под названием react-native-best-viewpager!
Установить с:
npm install --save react-native-best-viewpager
или с yarn install react-native-best-viewpager
помощью, если вы используете yarn.
Вот пример того, как его использовать:
import {StyleSheet, View, Text} from 'react-native';
import React, {Component} from 'react';
import {PagerTabIndicator, IndicatorViewPager} from 'react-native-best-viewpager';
export default class ViewPagerPage extends Component {
render() {
return (
<View style={{flex:1}}>
<IndicatorViewPager
style={{flex:1, paddingTop:20, backgroundColor:'white'}}
indicator={this._renderTabIndicator()}
>
<View style={{backgroundColor:'cadetblue'}}>
<Text>page one</Text>
</View>
<View style={{backgroundColor:'cornflowerblue'}}>
<Text>page two</Text>
</View>
<View style={{backgroundColor:'#1AA094'}}>
<Text>page three</Text>
</View>
</IndicatorViewPager>
</View>
);
}
_renderTabIndicator() {
let tabs = [{
text: 'Home',
iconSource: require('../imgs/ic_tab_home_normal.png'),
selectedIconSource: require('../imgs/ic_tab_home_click.png')
},{
text: 'Message',
iconSource: require('../imgs/ic_tab_task_normal.png'),
selectedIconSource: require('../imgs/ic_tab_task_click.png')
},{
text: 'Profile',
iconSource: require('../imgs/ic_tab_my_normal.png'),
selectedIconSource: require('../imgs/ic_tab_my_click.png')
}];
return <PagerTabIndicator tabs={tabs} />;
}
}