I am actually trying to use action buttons in React-native, but I have problems customizing action buttons position.
Using react-native-action-button (“react-native-action-button”: “^2.8.5”), buttons are positioned vertically, just like that:
But, I would like something where buttons are aligned horizontally, or as a “pyramid”, like the one in the center higher than the two others, aligned. A bit like that (the screen is from the MyFitnessPal app):
What could also be good is having a ‘transparent screen’ where action button are deployed, but that comes after.
Here is the code I am using :
JavaScript
x
65
65
1
import React, { Component } from 'react';
2
import { StyleSheet, View } from 'react-native';
3
import ActionButton from 'react-native-action-button';
4
import Icon from 'react-native-vector-icons/Ionicons';
5
6
7
class App extends Component {
8
9
render() {
10
return (
11
<View style={{flex:1, backgroundColor: '#f3f3f3'}}>
12
{/* Rest of the app comes ABOVE the action button component !*/}
13
<ActionButton
14
buttonColor="rgba(231,76,60,1)"
15
position = 'center'
16
verticalOrientation = 'up'
17
size = {70}
18
style = {{marginBottom: 100}}
19
>
20
{/*Inner options of the action button*/}
21
{/*Icons here
22
https://infinitered.github.io/ionicons-version-3-search/
23
*/}
24
<ActionButton.Item
25
buttonColor="#9b59b6"
26
title="Add to Watch Later"
27
onPress={() => this.props.navigation.navigate('Search')}>
28
<Ionicons
29
name="md-eye"
30
style={styles.actionButtonIcon}
31
/>
32
</ActionButton.Item>
33
<ActionButton.Item
34
buttonColor="#3498db"
35
title="Add to Favourite"
36
onPress={() => alert('Added to favourite')}>
37
<Ionicons
38
name="md-star"
39
style={styles.actionButtonIcon}
40
/>
41
</ActionButton.Item>
42
<ActionButton.Item
43
buttonColor="#1abc9c"
44
title="Share"
45
onPress={() => alert('Share Post')}>
46
<Ionicons
47
name="ios-beer"
48
style={styles.actionButtonIcon}
49
/>
50
</ActionButton.Item>
51
</ActionButton>
52
</View>
53
);
54
}
55
56
}
57
58
const styles = StyleSheet.create({
59
actionButtonIcon: {
60
fontSize: 20,
61
height: 22,
62
color: 'white',
63
},
64
});
65
Thank you in advance for your precious help !
Advertisement
Answer
Try using this approach!
JavaScript
1
50
50
1
import React from 'react';
2
import { View, Text, StyleSheet, TouchableWithoutFeedback, Animated, Dimensions } from 'react-native';
3
import { AntDesign, Entypo } from '@expo/vector-icons';
4
import ActionButton from 'react-native-action-button';
5
import { NavigationContainer } from '@react-navigation/native';
6
7
8
const width = Dimensions.get('window').width;
9
10
export default function Action({ navigation }) {
11
12
return (
13
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center', backgroundColor: '#fff', marginBottom: 70, marginRight: 20 }}>
14
<ActionButton buttonColor="#7E1FCD" position="right" >
15
<ActionButton.Item
16
buttonColor="#7E7A83"
17
size={34}
18
title="Time Blocker"
19
titleColor="red"
20
onPress={() => console.log("notes tapped!")}>
21
<AntDesign name="smileo" size={10} color="#FFF" />
22
</ActionButton.Item>
23
24
25
<ActionButton.Item buttonColor="#7E7A83"
26
size={34}
27
title="Book Resource"
28
onPress={() => console.log("notes tapped!")}>
29
<AntDesign name="smileo" size={10} color="#FFF" />
30
</ActionButton.Item>
31
32
<ActionButton.Item buttonColor="#7E7A83"
33
size={34}
34
title="New Class Session"
35
onPress={() => console.log("notes tapped!")}>
36
<AntDesign name="smileo" size={10} color="#FFF" />
37
</ActionButton.Item>
38
39
<ActionButton.Item buttonColor="#7E7A83"
40
size={34}
41
title="New Appointment"
42
onPress={() => navigation.navigate("Select")}>
43
<AntDesign name="smileo" size={10} color="#FFF" />
44
</ActionButton.Item>
45
</ActionButton>
46
</View>
47
);
48
49
}
50