I am new to react native and I am trying to achieve 2 buttons side by side I have tried it and I couldn't achieve it as I have already inserted 2 buttons it is appearing one below another
Here is my code:
<View style={styles.buttonStyle}>
<Button
title={"Pause"}
style={styles.buttonStyle}
onPress={() => {
this.setState({ paused: true });
}}
color="#841584"
/>
</View>
<View style={styles.buttonStyle}>
<Button
title={"Play"}
onPress={() => {
this.setState({ paused: false });
}}
color="green"
/>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
backgroundVideo: {
position: "absolute",
top: 0,
left: 0,
bottom: 0,
right: 0
},
buttonStyle: {
marginHorizontal: 20,
marginTop: 5
}
});
export default VideoPlayer;
Let’s create one starter react native project. Create one new file CButton.js with the below code : We are using TouchableOpacity for the button. One Text component is added for showing the title. text is passed to this component. width is 46% ,and height is 60. You can change these values to see how it looks.
This is an example of React Native Floating Action Button with Multiple Option. React Native Action Button is a kind of Floating Action Button with multiple options. You can also see the example of React Native Floating Action Button in which we set an onPress to do some action.
Here, we are adding two CButton with different text values. The wrapper View of these buttons is having flex = 1 with flexDirection = row and justifyContent as space-around. space-around adds paddings of the buttons on each side. Run it, and it will give one output as like below :
The property that defines rendering direction is called flexDirection, it can be set to column (default, render items vertically) or row (renders items horizontally).
So to achieve the desired effect you need to add the style property flexDirection:"row" to the View that contain the buttons. Your code would look something like:
<View style={{ flexDirection:"row" }}>
<View style={styles.buttonStyle}>
<Button>Button 1</Button>
</View>
<View style={styles.buttonStyle}>
<Button>Button 2</Button>
</View>
</View>
Try it out
<View style={{ flexDirection: "row" }}>
<View style={styles.buttonStyle}>
<Button title={"Button 11"}/>
<Button title={"Button 12"}/>
</View>
<View style={styles.buttonStyle}>
<Button title={"Button 21"}/>
<Button title={"Button 22"}/>
</View>
</View>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With