Center button at bottom center of view - css

I'm trying to center the next button at the bottom of the page. Instead of being at the bottom of the page it's stick in the middle of the page. Any help?
Screen shot:
Screen Shot
export default class Type extends Component {
constructor(props) {
super(props)
this.state = {
selected: 'user'
}
}
_select(selected) {
this.setState({ selected })
}
_renderButton(type, photo, width, height, buttonStyles) {
const { selected } = this.state
if (selected === type)
return (
<TouchableOpacity style={ styles.buttonSelected } onPress={ e => this._select(type) }>
<Image source={ photo } style={[ styles.buttonPhoto, buttonStyles ]} width={ width } height={ height } />
</TouchableOpacity>
)
return (
<TouchableOpacity style={ styles.button } onPress={ e => this._select(type) }>
<Image source={ photo } style={[ styles.buttonPhoto, buttonStyles ]} width={ width } height={ height } />
</TouchableOpacity>
)
}
_renderText(text, type, textStyles) {
const { selected } = this.state
if (selected === type)
return <Text style={[ styles.text, styles.textSelected, textStyles ]}>{ text }</Text>
return <Text style={[ styles.text, textStyles ]}>{ text }</Text>
}
render() {
return (
<ScrollView style={ styles.container }>
<Text style={ styles.question }>Who are you?</Text>
<View style={ styles.buttons }>
{ this._renderButton('user', boy, 64, 64, { top: 15, left: 20 }) }
{ this._renderButton('carnival', ticket, 72, 72, { top: 10, left: 15 })}
</View>
<View style={ styles.texts }>
{ this._renderText('Attendee', 'user', { left: -12 }) }
{ this._renderText('Carnival', 'carnival', { left: 8 }) }
</View>
<TouchableOpacity style={ styles.nextButton }>
<Text style={ styles.nextText }>
Next Step
</Text>
</TouchableOpacity>
</ScrollView>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1
},
question: {
paddingTop: '30%',
textAlign: 'center',
color: '#ccc',
fontSize: 24,
marginBottom: 30
},
buttons: {
flex: 1,
flexDirection: 'row',
justifyContent: 'center'
},
button: {
width: width/3,
height: width/3,
borderRadius: (width/3)/2,
borderWidth: 1,
borderColor: '#e6e6e6',
marginLeft: 10,
marginRight: 10
},
buttonPhoto: {
position: 'relative'
},
buttonSelected: {
width: width/3,
height: width/3,
borderRadius: (width/3)/2,
borderWidth: 1,
borderColor: '#ff9972',
marginLeft: 10,
marginRight: 10
},
texts: {
flex: 1,
flexDirection: 'row',
justifyContent: 'center',
paddingTop: 12
},
text: {
width: width/3,
color: '#b5b5b5',
textAlign: 'center',
},
textSelected: {
color: '#ff9972'
},
nextButton: {
position: 'absolute',
left: (width/1.5)/2,
bottom: 5,
paddingTop: 10,
backgroundColor: '#ff6b5d',
width: width/1.5,
height: 48,
borderRadius: 5,
borderBottomWidth: 2,
borderBottomColor: '#de5244',
},
nextText: {
fontSize: 16,
color: '#fff',
textAlign: 'center'
}
})
This has been giving me issues for hours now. Looking for a simple solution that is what professional developers use.
Ignore:
It looks like your post is mostly code; please add some more details.
It looks like your post is mostly code; please add some more details.
It looks like your post is mostly code; please add some more details.
It looks like your post is mostly code; please add some more details.

Instead of using <ScrollView> as Parent, you can use <ScrollView> inside of <View> and have something similar to the below structure.
<View>
<ScrollView style={{flex:1}}>
{/*All of your screen */}
</ScrollView>
<View>
<TouchableOpacity style={ styles.nextButton }>
<Text style={ styles.nextText }>
Next Step
</Text>
</TouchableOpacity>
</View>
</View>
The button will always stay at bottom of the page.

Related

React Native Sticky Footer Input got covered by Keyboard even using KeyboardAvoidingView

I have a basic chat application and when I open the keyboard I want the Sticky Chat Footer to persist at the top of the keyboard but its still being covered even when I use KeyboardAvoidingView.
Here is the image below:
And here is the image when keyboard is open:
Here is my component code below:
<SafeAreaView style={styles.scrollWrapper}>
<KeyboardAvoidingView
style={styles.scrollWrapper}
behavior="height"
keyboardVerticalOffset={headerHeight + 20}
>
<View style={styles.chatBar}>
<IconButton Icon={ButtonAdd} size={32} onPress={() => {}} />
{isKeyboardVisible ? (
<>
<RoundedInput
ref={inputRef}
itemStyle={styles.chatInput}
placeholder="type something here..."
RightComponent={(
<IconButton
Icon={EmojiIcon}
size={normalize(16.5)}
onPress={() => {}}
/>
)}
/>
<TouchableOpacity
activeOpacity={0.4}
onPress={handleKeyboardVisibility}
>
<Icon
style={styles.icon}
name="send-circle"
size={normalize(34)}
color="#F48C2D"
/>
</TouchableOpacity>
</>
) : (
<>
<IconButton
Icon={KeyboardIcon}
size={32}
onPress={handleKeyboardVisibility}
/>
<IconButton Icon={ChatCamera} size={32} onPress={() => {}} />
<IconButton Icon={GalleryIcon} size={32} onPress={() => {}} />
<IconButton Icon={GifIcon} size={32} onPress={() => {}} />
<IconButton Icon={LocationIcon} size={32} onPress={() => {}} />
</>
)}
</View>
</KeyboardAvoidingView>
</SafeAreaView>
and here is my style
const styles = StyleSheet.create({
header: {
...headerStyles.homeHeaderWrapper,
backgroundColor: '#F9F9F9',
borderBottomColor: '#D0D1D1',
},
scrollWrapper: {
flexGrow: 1,
backgroundColor: 'white',
},
dateWrapper: {
marginTop: normalize(12),
...helpers.center,
},
dateTxt: {
...fontHelper(10, typographyFonts.openSansRegular, '#212121', 0).font,
},
messageWrapper: {
flexDirection: 'row',
padding: normalize(12),
},
image: {
height: normalize(33),
width: normalize(33),
overflow: 'hidden',
borderRadius: 100,
alignSelf: 'center',
marginTop: normalize(12),
},
chatBubble: {
marginLeft: normalize(8),
maxWidth: '75%',
// height: normalize(77),
backgroundColor: '#F2F5F8',
borderRadius: 14,
// ...helpers.center,
padding: normalize(12),
marginVertical: normalize(5),
},
chatMsg: {
...fontHelper(13, typographyFonts.openSansRegular, '#212121', 0).font,
},
chatBar: {
height: normalize(65),
shadowOffset: { width: normalize(0), height: normalize(-1.25) },
// borderWidth: 5,
// borderBottomColor: 'red',
borderTopWidth: normalize(0.3),
borderTopColor: colors.alternative,
shadowColor: 'rgba(186,190,214,0.70)',
shadowOpacity: normalize(0.2),
shadowRadius: 2,
elevation: 5,
position: 'absolute',
left: 0,
right: 0,
bottom: 0,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-around',
zIndex: 999,
},
chatInput: {
height: normalize(35),
backgroundColor: '#FFFFFF',
borderColor: '#F48C2D',
borderWidth: 1,
width: '70%',
},
icon: {
width: normalize(34),
height: normalize(34),
},
});
I also already tried using react-native-keyboard-aware-scrollview but it didn't help as well.
Appreciate if someone could help.
I got the same issue.
Try this workaround.
You need to position your component on the top of the keyboard,
but it will depend on the size of device keyboard
import { Keyboard, Animated } from 'react-native'
...
useEffect(() => {
Keyboard.addListener('keyboardWillShow', _keyboardWillShow);
Keyboard.addListener('keyboardWillHide', _keyboardWillHide);
return () => {
Keyboard.removeListener('keyboardWillShow', _keyboardWillShow);
Keyboard.removeListener('keyboardWillHide', _keyboardWillHide);
}
}, []);
const _keyboardWillShow = (event) => {
const height = event.endCoordinates.height;
posComponent(height);
};
const _keyboardWillHide = (event) => {
posComponent(0);
};
const animateButton = (value) => {
Animated.spring(your_variable, {
toValue: value,
tension: 50,
friction: 10,
}).start();
}
then on your view component chatbar
<Animated.View style={{
...styles.chatBar,
...(Platform.OS === 'ios' && { bottom: your_variable })}>
...
</Animated.View>

What styles I have to write for alignment items (react-native)

I have a component with TextInput and another component which is called CompanyAddress. Each company can have many addresses, therefore I have to have "plus" button.
There are container styles
const AppStyles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#ffffff",
alignItems: "center",
justifyContent: "center"
},
inputStyle: {
height: 40,
width: '80%',
borderColor: '#28c9d9',
textAlign: 'center',
borderWidth: 1,
marginBottom: 20,
fontSize: 16
}
});
there is main component
<KeyboardAvoidingView behavior="padding" style={AppStyles.container}>
<TextInput
autoCompleteType="name"
placeholder="organization"
maxLength={30}
style={AppStyles.inputStyle}
onChangeText={(text) => { this.setState({name: text})} }
/>
<CompanyAddress/>
</KeyboardAvoidingView>
and there is CompanyAddress
class CompanyAddress extends React.Component<any, any> {
render() {
return (
<View style={styles.container}>
<TextInput
autoCompleteType="name"
placeholder="address"
maxLength={30}
style={[AppStyles.inputStyle, styles.textInput]}
/>
<AntDesign style={styles.plus} name="plus" size={24} color="black" />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
width: '100%',
flexDirection: 'row'
},
textInput: {
width: '70%',
},
plus: {
width: '30%'
}
});
but my CompanyAddress now looks like that
but I want to change styles for achieve that
you can add justifyContent:center to the container and for the children alignSelf:Center
ex:
<View style={{justifyContent : center,flexDirection:row}}>
<View style={{alignSelf:Center}}><View>
<View style={{alignSelf:Center}}><View>
</View>

react native list view design

I have tried to design the screen in react native but its hard divide a screen column and row like ionic and angular
Output of that below code
<View style={styles.listItemContainer}>
<View style={{flex:1}}>
<View style={{flexDirection:"column"}}>
<Text>1003234</Text>
<Text>Info Test........</Text>
</View>
</View>
<View style={{flexDirection:"column"}}>
<Text style={{backgroundColor:"red",borderRadius:10,padding:2,
marginRight:10,marginTop:5,fontSize:12}}>Inprogress</Text>
</View>
</View>`
exactly what i need
You can use Flatlist
Use below code to apply styles to your List
<FlatList style={Styles.container}
data={this.props.listData}
extraData={this.state.selectedItem}
keyExtractor={(item, index) => item.id}
renderItem={({ item, index }) => (
this.renderRow(item, index)
)}
ListEmptyComponent={this.showEmptyListView()}
/>
Your row render can look like this.
renderRow = (item, index) => {
return (
<TouchableHighlight key={index} onPress={() => this.onPressAction(item)} >
<View style={Styles.listItemContainer}>
<View style={Styles.listDesign}>
<View style={Styles.imageLength}>
{
item.imageUrl == '' ?
<Image
source={require("./../../assets/images/default-display.png")}
style={{ resizeMode: "cover", width: '100%', height: 100 }} /> :
<Image
source={{ uri: item.thumbnailImageUrl }}
style={{ resizeMode: "cover", width: '100%', height: 100 }} />
}
</View>
<View style={[Styles.columnAlign, Styles.contentWidth]}>
<View style={[Styles.justifyEnd, Styles.imageContainer]}>
<View style={Styles.justifySpaceAround}>
<Image
source={require("./../../assets/images/anyImage.png")}
style={{ resizeMode: "cover", width: 25, height: 25 }} />
</View>
</View>
<View style={Styles.buttonContainer}>
<Text style={Styles.vehicleDesc}>{"test"}</Text>
</View>
<View style={Styles.buttonContainer}>
<Text style={Styles.text}>{item.mileage}{translate("Test 1")}</Text>
</View>
<View style={Styles.buttonContainer}>
<Text style={Styles.text}>{"Test2"}</Text>
</View>
<View style={Styles.buttonContainer}>
<Text style={Styles.watchListtext}>{"Test 3"}</Text>
</View>
</View>
</View>
</View>
</TouchableHighlight>
);
}
Your Style
listItemContainer: {
marginTop: 7,
// marginBottom: 7,
flexDirection: 'row',
alignItems: 'flex-start',
},
listDesign: {
backgroundColor: Colors.white,
flexDirection: 'row',
alignItems: 'center',
padding: 6,
width: '100%'
},
vehicleDesc: {
marginLeft: 12,
fontSize: 16,
color: '#AA2328',
fontWeight: 'bold'
},
text: {
marginLeft: 12,
fontSize: 14,
color: Colors.black,
},
watchListtext: {
marginLeft: 12,
fontSize: 14,
color: Colors.brandPrimary,
},
imageLength: {
width: '35%'
},
contentLength: {
width: '65%'
},
container: {
flex: 1,
backgroundColor: Colors.creamyWhite,
},
buttonContainer: {
flexDirection: 'row',
padding: 2
}, imageContainer: {
flexDirection: 'row',
},
justifySpaceAround:
{
justifyContent:'space-around'
}
justifyEnd:
{
justifyContent:'flex-end'
},
coulmnAlign:
{
flexDirection:'coumn'
}
You show empty data
showEmptyListView = () => {
return (
<View style={{ flex: 1, flexDirection: 'column', alignItems: 'center', justifyContent: 'center', padding: 10 }}>
<Text style={{ color: Colors.white }}>{"No Data to Display"}</Text>
</View>
)
}
You have to handle a lot in style.
You only need 3 common tag:
HorizontalContainer,
VerticalContainer,
ItemContainer,
export const VerticalContainer = styled.View({
flex: 1,
flexDirection: "column",
backgroundColor: (props) => props.backgroundColor || "#000"
});
export const HorizontalContainer = styled.View({
flex: 1,
flexDirection: "row",
backgroundColor: (props) => props.backgroundColor || "#000"
});
export const ItemContainer = styled.View({
flex: (props) => props.flex || 1
});
Inside handle as you like:
<HorizontalContainer backgroundColor="#fff">
<ItemContainer/>
<ItemContainer flex=2></ItemContainer>
<ItemContainer />
</HorizontalContainer >
Hope to help you!
I have done it with My Own code(FlatList view with design and search bar data from api) In that code i have removed my api call services you can try your own
Output Here(Check Before You Try)
import React, { Component } from 'react';
import { View, Text, StyleSheet,FlatList,ScrollView,ActivityIndicator} from 'react-native';
import { Picker } from 'react-native-picker-dropdown';
import Icon5 from 'react-native-vector-icons/FontAwesome5';
import { SearchBar, Avatar } from 'react-native-elements';
// create a component
class Home extends Component {
constructor(props){
super(props);
this.state={
data:[],
text: '',
language:'self',
ready: false,
searchText: "",
filteredData: [],
backupData:[]
}
this.onValueChange = this.handleValueChange.bind(this)
this.arrayholder=[];
}
search (searchText) {
this.setState({searchText: searchText});
console.log(searchText)
let text = searchText.toLowerCase();
let trucks = this.state.data;
// search by food truck name
let filteredName = trucks.filter((truck) => {
return truck.title.toLowerCase().match(text);
});
// if no match and text is empty
if( text == '') {
console.log('change state');
this.setState({
data: this.state.backupData
});
}
else if(!text ){
console.log("myname")
this.setState({data:[]})
}
// if no name matches to text output
else if(!Array.isArray(filteredName) && !filteredName.length) {
console.log("not name");
this.setState({
data: [],
});
}
// if name matches then display
else if(Array.isArray(filteredName)) {
console.log('Name');
this.setState({
data: filteredName,
});
}
};
showEmptyListView = () => {
return (
<View style={{ flex: 1, flexDirection: 'column', alignItems: 'center', justifyContent: 'center', padding: 10 }}>
<Text style={{ color: "black" }}>{"No Data to Display"}</Text>
</View>
)
}
handleValueChange(language) {
this.setState({ language })
}
renderRow = (item, index) => {
return (
<View style={styles.listItemContainer}>
<View style={{flex:1}}>
<View style={{flexDirection:"column",alignItems:"flex-start"}}>
<View style={{flexDirection:"row"}}>
<Text style={{marginLeft:12,marginTop:5,marginBottom:5,fontWeight:"bold",color:"black"}}>{item.number}</Text>
<Icon5 name="arrow-circle-up" size={15} style={{ marginTop:8,marginLeft:8, color: '#af2a5b', }}/>
<Text style={{marginLeft:5,marginTop:5,marginBottom:5,fontWeight:"bold",color:"#af2a5b"}}>{item.priority}</Text>
</View>
<Text style={{marginLeft:12,marginBottom:5,fontWeight:"bold",color:"black"}}>{item.title}</Text>
<View style={{flexDirection:"row"}}>
<Icon5 name="calendar-alt" size={15} style={{ marginLeft:12,marginBottom:5 }}/>
<Text style={{marginLeft:8,marginBottom:5}}>{item.assignedDate}</Text>
</View>
<View style={{flexDirection:"row"}}>
<Icon5 name="user-alt" size={15} style={{ marginLeft:12,marginBottom:5 }}/>
<Text style={{marginLeft:8,marginBottom:5}}>{item.createdBy}</Text>
</View>
</View>
</View>
<View style={{flexDirection:"column"}}>
<Text style={{color:"#f6b073",backgroundColor:"#fcd8b8",borderRadius: 10,padding:3,marginRight:10,marginTop:5,fontSize:12}}>{item.state}</Text>
</View>
</View>
);
}
renderHeader = () => {
return(
<View style={{ flex: 1, flexDirection: 'column' }}>
<View style={styles.listItemContainer}>
<View style={{flexDirection: 'row',backgroundColor: '#fff',color: '#fff',
width: '100%',height: 43,}}>
<View style={{ flex: 1, flexDirection: 'row' }}>
<View style={{ width: '45%', justifyContent: 'center', paddingTop: 7, paddingBottom: 7, color: '#fff', }} >
<Picker mode="dropdown" style={{width:150}}
selectedValue={this.state.language}
onValueChange={this.onValueChange} >
<Picker.Item label="My Task" value="self" />
<Picker.Item label="My Group" value="group" />
</Picker>
</View>
<View style={{ width: '55%', justifyContent: 'center', paddingTop: 7, paddingBottom: 7, color: '#fff', }} >
<SearchBar
inputStyle={{ backgroundColor: 'white', borderRadius: 55, borderWidth: 0, borderTopWidth: 0, borderBottomWidth: 0, height: 25 }}
containerStyle={{ backgroundColor: 'white', borderColor: '#g5g5g5', borderWidth: 0, borderRadius: 55, borderTopWidth: 0, borderBottomWidth: 0, width: '100%', marginLeft: 0, marginRight: 0, marginTop: 10, marginBottom: 10, height: 40 }}
placeholder="Search Here..."
inputContainerStyle={{ backgroundColor: 'white', borderWidth: 0, borderRadius: 55, height: 25 }}
onChangeText={searchText => this.search(searchText)}
value={this.state.searchText}
/>
</View>
</View>
</View>
</View>
</View>
)
}
renderFooter = () => {
return(
<View>
<Text>Footer</Text>
</View>
)
}
render() {
if (this.state.ready) {
return (
<FlatList style={{flex: 1,}}
data={this.state.filteredData && this.state.filteredData.length > 0 ? this.state.filteredData : this.state.data}
renderItem={({ item, index }) => (
this.renderRow(item, index)
)}
keyExtractor={(item, index) => index}
ListHeaderComponent={this.renderHeader}
ListEmptyComponent={this.showEmptyListView()}
enableEmptySections={true}
style={{flexWrap: 'wrap'}}
/>
);
}
else{
return (
<ActivityIndicator
animating={true}
style={{flex: 1,
alignItems: 'center',
justifyContent: 'center',
height: 80}}
color="#2F80ED"
size="large"
/>
);
}
}
}
const styles = StyleSheet.create({
listItemContainer: {
flex: 1,
marginBottom:10,
// paddingBottom: 15,
flexDirection: 'row',
backgroundColor: '#fff',
alignItems: 'flex-start',
},
})
export default Home;

How to make a shadow only for the container, not for inside element

I have an app on react-native. I need to make a shadow for the particular View. When i set it the shadow is working only for the inside of a View elements, but i need the shadow only for the border of View, not for the inside elements. Can you tell me please how can i do it?
const styles = StyleSheet.create({
container: {
alignItems: 'center',
height: HP('11.2%'),
justifyContent: 'center',
width: '100%'
},
icon: {
color: '#757575',
position: 'absolute'
},
inputContainer: {
width: '85%'
},
subContainer: {
alignItems: 'center',
borderRadius: HP('6.8%'),
borderWidth: 1,
borderColor: 'rgba(0, 0, 0, 0.24)',
flexDirection: 'row',
height: HP('7.8%'),
width: WP('95%')
},
shadowStyle: {
shadowColor: '#000',
shadowOffset: {
width: 0,
height: 1
},
shadowOpacity: 0.22,
shadowRadius: 2.22,
elevation: 3
},
textInput: {
fontFamily: 'Roboto',
fontSize: HP('2.3%'),
height: 48,
maxWidth: '85%',
left: WP('9%')
}
})
const SearchBar = props => {
const { container, icon, inputContainer, subContainer, shadowStyle, textInput } = styles
const { onChangeText, onLeftIconPress, onRightIconPress, value } = props
return (
<View style={[container, shadowStyle]}>
<View style={[shadowStyle, subContainer]}>
<TouchableOpacity onPress={onLeftIconPress}>
<Ionicons style={(icon, { left: WP('5%') })} name="md-funnel" size={HP('3.5%')} />
</TouchableOpacity>
<View style={inputContainer}>
<TextInput
autoCapitalize="words"
onChangeText={onChangeText}
placeholder="Search.."
style={textInput}
value={value}
/>
</View>
<TouchableOpacity onPress={onRightIconPress}>
<Ionicons style={(icon, { right: WP('0.3%') })} name="ios-mic" size={HP('4%')} />
</TouchableOpacity>
</View>
</View>
)
}

Flexbox in react native : How to align 2 items at the center of the screen?

I discovered flexbox recently and I'm struggling to make it work, I'm surely missed some concept that make me hard time to understands it's mechanics so here is what I have:
It's a preview camera screen
with a back button on the top right
A text in the middle
and a record button to shoot some images
Here is what I have at the moment:
this is done with this React native component (style included)
import React from "react";
import { RNCamera } from "react-native-camera";
import { StyleSheet, TouchableOpacity, View, Platform} from "react-native";
import {Icon, Text} from "native-base";
import RequestPermissions from "../components/Permissions/RequestPermissions";
import I18n from "../i18n/i18n";
/**
* This is the component which allows the user to film his own film
*/
export default class CameraScreen extends React.Component
{
constructor(props) {
super(props);
this.camera = null;
}
state = {
isRecording: false,
iconVid: "record",
iconMode: null,
overlay: true
};
/**
* With RNCamera, it seems that permission is always asked to the user... Maybe this code is then irrelevant
*/
componentWillMount() {
if (Platform.OS === "android") {
RequestPermissions().then(() => {
console.log("granted");
}).then((err) => {
console.log(err)
});
}
}
componentWillUnmount() {
this.stopRecording();
};
stopRecording = () => {
if (this.camera) {
this.camera.stopRecording();
this.setState({
isRecording: false,
iconVid: "record"
});
}
};
renderCamera = () => {
return (
<View style={styles.container}>
<RNCamera
ref={cam => {
this.camera = cam;
}}
style={styles.preview}
>
<View style={styles.controlsContainer}>
<View style={styles.topRightButton}>
<TouchableOpacity onPress={() => this.props.navigation.goBack()}>
<Icon name={"arrow-left"} type={"Feather"} style={styles.iconFurtive}/>
</TouchableOpacity>
</View>
<View style={styles.middleContainer}>
<Text style={styles.actionText}>{I18n.t("action_text").toUpperCase()}</Text>
</View>
<View style={styles.leftContainer}>
<TouchableOpacity onPress={() => this.recordVideo()}>
<Icon name={this.state.iconVid} type={"MaterialCommunityIcons"} style={styles.iconCamera}/>
</TouchableOpacity>
</View>
</View>
</RNCamera>
</View>
);
};
/**
* For more options
* https://github.com/react-native-community/react-native-camera/blob/master/docs/RNCamera.md#recordasyncoptions-promise
*/
recordVideo = () => {
if (this.camera) {
this.setState({ isRecording: true, iconVid: "stop" });
// Show the overlay
console.log("Device is Recording");
this.camera.recordAsync({maxDuration: 15}).then(data => {
this.stopRecording();
console.log("Stop Recording");
console.log(data);
}).catch((err) => {
console.log(err);
this.stopRecording();
});
}
};
render() {
return this.renderCamera()
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
marginTop:30,
},
controlsContainer: {
flex: 1,
flexDirection: "column"
},
topRightButton: {
flex: 1,
justifyContent: 'flex-start',
alignItems: 'flex-start',
},
middleContainer: {
flex: 0.5,
justifyContent: 'center',
alignItems: 'center',
},
leftContainer: {
flex: 0.5,
justifyContent: 'center',
alignItems: 'flex-end',
},
actionText: {
color: "#fff",
fontSize: 72
},
preview: {
flex: 1,
},
iconCamera: {
color: "#ff4459",
marginBottom: 50,
padding: 25,
backgroundColor: "#fff",
borderRadius: 50,
},
iconFurtive: {
color: "#fff",
marginTop: 50,
marginLeft: 50,
}
});
Here is what I want:
How to do that with flexbox? What am I missing?
Code changed at View with {styles.topRightButton}
return (
<View style={styles.container}>
<RNCamera
ref={cam => {
this.camera = cam;
}}
style={styles.preview}
>
<View style={styles.controlsContainer}>
<View style={{justifyContent: 'flex-start', alignItems: 'flex-start',}}>
<TouchableOpacity onPress={() => this.props.navigation.goBack()}>
<Icon name={"arrow-left"} type={"Feather"} style={styles.iconFurtive}/>
</TouchableOpacity>
</View>
<View style={{flex: 1, flexDirection: 'row', alignItems: 'center', justifyContent: 'space-around'}}>
<View style ={{height: 50, width: 50, backgroundColor: 'transparent'}} />
<Text style={styles.actionText}>{I18n.t("action_text").toUpperCase()}</Text>
<TouchableOpacity onPress={() => this.recordVideo()}>
<Icon name={this.state.iconVid} type={"MaterialCommunityIcons"}/>
</TouchableOpacity>
</View>
</View>
</RNCamera>
</View>
);
For middle and left the content should be in the same div with that div having a flexDrirection: 'row'. This puts them in the same row.
The controls container can have justifyContent: 'center', and alignItems: 'center'.
The topRightButton should override the parents style.

Resources