I'm building a react-native app. Basically, it has a BottomTabNavigation for navigating through the screens.
In one of my screens, I want to open another screen with a BottomTabNavigation to navigate to other screens inside.
Unfortunately, I haven't found something on Google or in the search function. Is this possible to create?
You can do it easily using a module called react-native-best-viewpager!
Install with:
npm install --save react-native-best-viewpager or with yarn install react-native-best-viewpager if you're using yarn.
Here's an example of how to use it:
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} />;
}
}
Related
I have the following code:
import React, {Component} from 'react';
import {Platform, ScrollView, StyleSheet, Text, TextInput, TouchableOpacity, View,} from 'react-native';
import {Alert} from "react-native-web";
export default class HomeScreen extends Component {
state = {text: ''};
_onPressSearch() {
Alert.alert("Button pressed!")
}
render() {
return (<View style={styles.container}>
<ScrollView style={styles.scrollViewContainer} contentContainerStyle={styles.contentContainer}>
<View style={styles.searchContainer}>
<TextInput placeHolder="Type something!" onChangeText={(text) => this.setState({text})}
value={this.state.text}/>
</View>
<TouchableOpacity
onPress={this._onPressSearch}>
<View>
<Text>Search</Text>
</View>
</TouchableOpacity>
<View style={styles.listContainer}>
<Text>{this.state.text}</Text>
</View>
</ScrollView>
</View>
And my problem is that when I click on TouchableOpacity no action happens (in my case showing alert). I tried to change ToachableOpacity and View combination to usual button but nothing happened again. So, what's the problem and how can I solve it?
Looking at the docs looks like Alert is not completed yet (https://github.com/necolas/react-native-web) inside react-native-web.
This is the issue about the react-native-web alert: https://github.com/necolas/react-native-web/issues/1026
Try using default javascript alert doing alert("Button pressed!") or importing Alert from react-native
The code looks fine
I am trying to load a remote placeholder image. The first image is a local image and loads properly, but not the second image. I am testing this on an android device so I don't think https would cause problems.
Any hints to what I might be doing wrong?
import React, { Component } from 'react';
import { Text, View, Dimensions, TouchableOpacity, Image, ToastAndroid, Animated } from 'react-native';
import styles from "./styles";
class Story extends Component {
constructor(props){
super(props);
this.state={};
}
render() {
return (
<View style={{position:'relative'}}>
<Image source={require('app/assets/images/campus.png')} style={styles.container}></Image>
<Image source={{ uri: 'https://place-hold.it/100x200/fdd.png' }} style={styles.character1}></Image>
</View>
);
}
}
export default Story;
// firstly set isImageload false
then implement image like this
var image= this.state.isImageload ? require('place holder image') : {uri: ImageUrl};
return(
<Image
source={immage}
onLoadStart={() => this.setState({isImageload : true})}
onLoad={() => this.setState({isImageload : false})}
/>
)
I removed one pair bracket from the Image tag and the code become:
<Image source={ uri: 'https://place-hold.it/100x200/fdd.png' } style={styles.character1}></Image>
Please try it to see whether if works.
I have use this reference url https://snack.expo.io/HkjxvRS-W for adding Picker in React Native, but here it's show only one wheel in Picker, but I want to display two wheel in Picker, so how do I do it ? is anyone have any idea?
import React, { Component } from 'react';
import { Text, View, StyleSheet, Picker } from 'react-native';
export default class HomePage extends Component {
constructor(props) {
super(props);
this.state = {
selectedValue: ''
arrayPickers: ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten']
}
}
render() {
return (
<View style={styles.container}>
<Picker
style={{width: 320}}
selectedValue={this.state.selectedValue}
onValueChange={(value) => this.setState({selectedValue: value})}>
{this.state.arrayPickers.map((value, index) => (
<Picker.Item label={value} value={value} key={index} />
))}
</Picker>
</View>
);
}
}
From Above code I am able to show one Wheel or Component in Picker, but I want to show two Wheel or Component in Picker.
Please have look below image for further understanding.
Picker
Here is a library that you can use to achieve what you want react-native-picker, as didn't specify how you wanted or posted any source code, I feel like this could help you.
Current Behavior
My code:
class App extends Component {
render() {
return <Drawer /> {/* rigid scrolling effect */}
return <Stack /> {/* smooth scrolling effect if I comment above return statement */}
}
}
const Drawer = DrawerNavigator({
Feed: { screen: Feed }
})
const Stack = StackNavigator({
Feed: { screen: Feed }
})
And Feed component's render is just a bunch of lines:
render() {
return <View style={{flex:1}}>
<ScrollView>
<Text>random line...</Text>
// .. more lines to make it scrollable
</ScrollView>
</View>
}
Expected Behavior
The expected behavior is to get smooth scrolling effect in both cases. However, DrawerNavigator screen's scrolling effect is extremely rigid. When I swipe my finger quickly from up to down, it doesn't keep scrolling smoothly automatically like it should in Stacknavigator example.
How to reproduce
Create App.js file above and create a simple Feed.js component which has a bunch of lines to make ScrollView work.
Can anybody help?
Update: Live demonstration: https://snack.expo.io/Hk8Np7nPG
Try this
render() {
return (
<View style={{flex:1}}>
<ScrollView>
<View>
{Your Contnet}
</View>
</ScrollView>
</View>
)}
it is worked for me...
hope it'll also worked for you
You can Use NativeBase with standard tabs Container and Contet (like ScrollView ) Header and...
first try :
npm install native-base --save
then:
npm i
react-native link
and here is your full example code:
import React, { Component } from 'react';
import { Content , View , Text } from 'native-base'; //don't need import 'react-native' components
export default class GeneralExample extends Component {
render() {
return (
<Content >
<View>
{Your Contnet}
</View>
</Content>
)}
}
and if you wanna change the speed just ScrollView try:
<ScrollView decelerationRate={0.5}>
<View/>
</ScrollView>
in NativeBase Use THIS LINK
I have a simple two page set up using the NavigatorIOS for an iOS app using React Native. After my app loads, I can click into the second page but when I click back (top left) then I get the following error:
Unsupported top level event type "topScroll" dispatched
extractEvents
ReactNativeFiber-dev.js:3519:22
extractEvents
ReactNativeFiber-dev.js:3298:71
handleTopLevel
ReactNativeFiber-dev.js:3539:64
<unknown>
ReactNativeFiber-dev.js:3560:55
batchedUpdates
ReactNativeFiber-dev.js:2754:26
batchedUpdatesWithControlledComponents
ReactNativeFiber-dev.js:209:34
_receiveRootNodeIDEvent
ReactNativeFiber-dev.js:3559:50
receiveEvent
ReactNativeFiber-dev.js:3564:60
__callFunction
MessageQueue.js:302:47
<unknown>
MessageQueue.js:116:26
__guard
MessageQueue.js:265:6
callFunctionReturnFlushedQueue
MessageQueue.js:115:17
The error occurs when running in the simulator and on the device (from xcode).
This is the code to my application. I'm sure I didn't initialize something correctly, I just don't seem to be able to find out what that is:
'use strict';
import React, { Component } from 'react';
import {
StyleSheet,
Button,
Text,
View,
NavigatorIOS
} from 'react-native';
const styles = StyleSheet.create({
container: {
flex: 1,
},
scene: {
padding: 10,
paddingTop: 74,
flex: 1,
}
})
class PageFeedItem extends Component {
render() {
return(
<View style={styles.scene}>
<Text>Some text</Text>
</View>
);
}
}
class PageFeed extends Component {
constructor(props, context) {
super(props, context);
this.onShowFeedItem = this.onShowFeedItem.bind(this);
}
onShowFeedItem() {
this.props.navigator.push({
component: PageFeedItem,
title: "Feed Item",
passProps: {}
});
}
render() {
return(
<View style={styles.scene}>
<Text>Feeds</Text>
<Button onPress={this.onShowFeedItem} title="Show Item"/>
</View>
);
}
}
class Main extends Component {
render() {
return (
<NavigatorIOS
style={styles.container}
initialRoute={{
component: PageFeed,
title: 'Home',
passProps: {},
}}
/>
);
}
}
export default Main;
UPDATE
Two things I have noticed since asking this question:
1) When the error occurs, by pressing ESC, the application seems to continue without problems.
2) Adding a Button to the second page and adding a handler to do a this.props.navigator.pop(); seems to work fine, i.e. doesn't resolve in an error.
i also faced same issue and then changed the react-native version from 0.50 to 0.49.* and everything works. its an known bug in latest version of react native
Wrap the screen with ScrollView.
render() {
return (
<ScrollView>
<View>
<Text>Test screen</Text>
</View>
</ScrollView>
);
}
}
Try to add this code in PageFeed class:
static propTypes = {
title: PropTypes.string.isRequired,
navigator: PropTypes.object.isRequired,
}
Adding directionalLockEnabled={false} to ScrollView solved it for me.
Found it here: https://github.com/facebook/react-native/issues/2962#issuecomment-142768841