React Native: White space around image - react-native

I am not able to remove white space around the "PRACTICIA" logo image and so my buttons are being pushed down to the bottom. Can someone please help me with this? My code is here
My screenshot is down at the bottom. Here is the code for the entire app, its in the app.js file.
import React from 'react';
import { StyleSheet, Text, View, Image } from 'react-native';
import { StackNavigator } from 'react-navigation';
import {
Button,
FormLabel,
FormInput,
FormValidationMessage,
Divider } from 'react-native-elements';
import { CardSection } from './src/components/CardSection';
class HomeScreen extends React.Component {
static navigationOptions = {
title: 'PRACTICIA'
};
render() {
const { navigate } = this.props.navigation;
return (
<View style={{ backgroundColor: 'white', flex: 1 }}>
<Image
style={{ flex: 1, height: 100, width: undefined }}
resizeMode="contain" source={require('./images/practicialogo.png')}
/>
<Text style={styles.textStyle}>Sign up as a...</Text>
<Divider style={{ height: 10, backgroundColor: 'white' }} />
<Button
raised
backgroundColor="#3399ff"
borderRadius={20}
onPress={() => navigate('Teacher')}
title="TEACHER"
/>
<Divider style={{ height: 10, backgroundColor: 'white' }} />
<Button
raised
backgroundColor="green"
borderRadius={20}
onPress={() => navigate('Parent')}
title="PARENT"
/>
<Divider style={{ height: 10, backgroundColor: 'white' }} />
<Button
raised
backgroundColor="brown"
borderRadius={20}
onPress={() => navigate('Student')}
title="ADULT STUDENT (18+)"
/>
<Text style={styles.text2Style}>Already Registered?</Text>
<Button
raised
flex='2'
backgroundColor="grey"
borderRadius={20}
onPress={() => navigate('Login')}
title="Login"
/>
</View>
);
}
}
class TeacherSignUp extends React.Component {
static navigationOptions = {
title: 'TEACHER SIGN UP',
};
render() {
return (
<View style={{ backgroundColor: 'white', flex: 1 }}>
<Divider style={{ height: 20, backgroundColor: 'white' }} />
<Text style={styles.textStyle}>Sign Up</Text>
<FormLabel>Email</FormLabel>
<FormInput />
<FormLabel>Password</FormLabel>
<FormInput />
<FormLabel>First Name</FormLabel>
<FormInput />
<FormLabel>LastNme</FormLabel>
<FormInput />
<Divider style={{ height: 10, backgroundColor: 'white' }} />
<Button
raised
backgroundColor="brown"
borderRadius={0}
// onPress={() => navigate()}
title="SUBMIT"
/>
</View>
);
}
}
class ParentSignUp extends React.Component {
static navigationOptions = {
title: 'PARENT SIGN UP',
};
render() {
return (
<View style={{ backgroundColor: 'white', flex: 1 }}>
<Text>Sign Up</Text>
</View>
);
}
}
class StudentSignUp extends React.Component {
static navigationOptions = {
title: 'ADULT STUDENT SIGN UP',
};
render() {
return (
<View style={{ backgroundColor: 'white', flex: 1 }}>
<Text>Sign Up</Text>
</View>
);
}
}
class Login extends React.Component {
static navigationOptions = {
title: 'LOGIN',
};
render() {
return (
<View style={{ backgroundColor: 'white', flex: 1 }}>
<FormLabel>Email/Username</FormLabel>
<FormInput />
<FormLabel>Password</FormLabel>
<FormInput />
<Divider style={{ height: 10, backgroundColor: 'white' }} />
<Button
raised
backgroundColor="grey"
borderRadius={0}
// onPress={() => navigate()}
title="SUBMIT"
/>
</View>
);
}
}
const SimpleApp = StackNavigator({
Home: { screen: HomeScreen },
Teacher: { screen: TeacherSignUp },
Parent: { screen: ParentSignUp },
Student: { screen: StudentSignUp },
Login: { screen: Login },
});
export default class App extends React.Component {
render() {
return <SimpleApp />;
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'white',
alignItems: 'center',
justifyContent: 'center'
},
textStyle: {
alignSelf: 'center',
color: '#617189',
fontSize: 20,
fontWeight: '600',
paddingTop: 10,
paddingBottom: 10
},
text2Style: {
alignSelf: 'center',
color: '#617189',
fontSize: 14,
fontWeight: '300',
paddingTop: 10,
paddingBottom: 10
},
titleText: {
fontSize: 20,
fontWeight: 'bold',
},
});
here is the screenshot, there should not be that much white space around the logo:
Here is the, image, which does not have that much white space, so i dont understand where the white space is coming from:

Thanks All,
I believe the answer lies in the flex property. giving the image a prop of flex:1 will take up the entire container. So i played around with giving it a relative value and started with "1 / 2" (according to EsLint, those spaces in fraction are required). this at once solved the problem! I then played around with making the fraction larger and larger (3 / 4, 4 / 5, 7 / 8 etc.) till i got to where i wanted to be. This seemed to solve the issue. Result is below. Not sure its the only solution or even the best solution but it seems to work. Happy to receive feedback and commentary.
Revised line of code:
style={{ flex: 7 / 8, height: undefined, width: undefined }}

Related

How to open a facebook, instagram.. (social network) profile from my app

I'm creating an application using react native and I need to allow user to open all the available social networks of another user.
I saw that question and this one, but they doesn't works for me.
can anyone help
EDIT
I know how to create icons and call social networks' website, however, what I want is to open a user profile in a social networks app
I remarked that for instagram, the user profile url, opens the app, howover for Fb, it opens the website,
This following is used in my project. Its the contact US page of my react native app.
Works fine for me.
import React, { Component } from 'react';
import { StyleSheet, Text, Dimensions, View, TouchableNativeFeedback, TouchableOpacity, Image, Linking, ScrollView, Platform } from 'react-native';
import { Icon, Card, CardItem } from 'native-base';
import Colors from '../config/Colors';
import Dimens from '../config/Dimens';
import { RNToasty } from 'react-native-toasty';
import OneSignal from 'react-native-onesignal';
import { getStatusBarHeight } from 'react-native-status-bar-height';
import { colors } from 'react-native-elements';
import { Header } from 'react-navigation';
import HeaderBackground from '../components/HeaderBackground';
var width = Dimensions.get('window').width;
var height = Dimensions.get('window').height;
class SocialMedia extends Component {
constructor(props) {
super(props);
}
static navigationOptions = ({ navigation }) => {
return {
header: (props) => <HeaderBackground {...props} />,
headerStyle: {
backgroundColor: Colors.transparent,
paddingTop: Platform.OS === 'ios' ? 0 : getStatusBarHeight(),
height: Header.HEIGHT + (Platform.OS === 'ios' ? 0 : getStatusBarHeight()),
},
title: 'Social Media',
headerTintColor: Colors.white,
headerTitleStyle: {
fontWeight: 'bold',
padding: 5,
paddingTop: 10
},
headerMode: 'float',
headerLeft: <Icon
onPress={() => navigation.goBack()}
name="arrow-back"
type='MaterialIcons'
style={{ color: 'white', marginLeft: 10, padding: 5, paddingTop: 10 }}
/>,
}
}
render() {
return (
<View style={styles.container}>
<View style={styles.cardContainer}>
<TouchableOpacity background={TouchableNativeFeedback.Ripple(Colors.secondaryColor, false)} onPress={() => { Linking.openURL('https://www.facebook.com/max/') }}>
<Card style={styles.card}>
<CardItem style={styles.cardBody}>
<Image source={require('../assets/icons/Contact_Facebook.jpg')} style={styles.icon} resizeMode='contain' />
<Text style={styles.iconText}>Facebook</Text>
</CardItem>
</Card>
</TouchableOpacity>
<TouchableOpacity background={TouchableNativeFeedback.Ripple(Colors.secondaryColor, false)} onPress={() => { Linking.openURL('https://www.instagram.com/max/') }}>
<Card style={styles.card}>
<CardItem style={styles.cardBody}>
<Image source={require('../assets/icons/Contact_Insta.jpg')} style={styles.icon} resizeMode='contain' />
<Text style={styles.iconText}>Instagram</Text>
</CardItem>
</Card>
</TouchableOpacity>
<TouchableOpacity background={TouchableNativeFeedback.Ripple(Colors.secondaryColor, false)} onPress={() => { Linking.openURL('https://www.youtube.com/channel/UCnQoipGmBRC1XTOUY8c1UdA') }}>
<Card style={styles.card}>
<CardItem style={styles.cardBody}>
<Image source={require('../assets/icons/Contact_YT.jpg')} style={styles.icon} resizeMode='contain' />
<Text style={styles.iconText}>YouTube</Text>
</CardItem>
</Card>
</TouchableOpacity>
<TouchableOpacity background={TouchableNativeFeedback.Ripple(Colors.secondaryColor, false)} onPress={() => { Linking.openURL('https://max.com/') }}>
<Card style={styles.card}>
<CardItem style={styles.cardBody}>
<Image source={require('../assets/icons/Contact_web.jpg')} style={styles.icon} resizeMode='contain' />
<Text style={styles.iconText}>Website</Text>
</CardItem>
</Card>
</TouchableOpacity>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 8
},
contentContainer: {
paddingBottom: 20
},
cardContainer: {
flex: 1,
padding: 5,
width: '100%',
},
card: {
padding: 5,
height: height * .20,
width: '100%',
backgroundColor: '#fff',
flexDirection: 'column',
//alignItems: 'center',
//justifyContent: 'center',
shadowColor: '#1A9EAEFF',
shadowOffset: { width: 3, height: 3 },
shadowOpacity: 3,
shadowRadius: 2,
elevation: 10,
borderRadius: 5,
overflow: 'hidden'
},
cardBody: {
flex: 1,
flexDirection: 'row',
},
iconText: {
flex: 1,
fontWeight: 'bold',
alignItems: 'center',
justifyContent: 'center',
fontSize: 18,
color: '#1A9EAEFF'
},
icon: {
flex: 1,
width: '100%',
height: width * .18,
},
});
export default SocialMedia;
Hope this helps..
You're good to go!!
For instagram this is working for me,
Linking.openURL('https://www.instagram.com/profile_username/');
for facebook its just opening the facebook app.
Linking.openURL('fb://profile_username/');

How to implement time picker functionality in react native

I want to implement a functionality that should allow me to pick time within a range.
it should be like this
I have used react-native-slider and my code is here
import React, { Component } from 'react';
import { View, Text, Image, TextInput, StyleSheet } from 'react-native';
import Slider from 'react-native-slider';
import colors from '../styles/colors';
import Strings from '../localization/strings';
class FindDoctor extends Component {
constructor(props) {
super(props);
this.state = {
value: 6,
};
}
getInitialState() {
return {
value: 2,
};
}
render() {
return (
<View style={styles.container}>
<View style={{ flexDirection: 'column', margin: 20 }}>
<Text style={styles.textStyle}>Looking for</Text>
<View style={styles.input}>
<TextInput
placeholder={Strings.InternalMedicine}
autoCorrect={this.props.autoCorrect}
autoCapitalize={this.props.autoCapitalize}
returnKeyType={this.props.returnKeyType}
placeholderTextColor={colors.dimgray}
underlineColorAndroid="transparent"
onChangeText={TextInputName => this.setState({ TextInputName })}
/>
</View>
</View>
<View style={{ flexDirection: 'column', margin: 20 }}>
<Text style={styles.textStyle}>Near</Text>
<View style={styles.input}>
<TextInput
placeholder={Strings.Place}
autoCorrect={this.props.autoCorrect}
autoCapitalize={this.props.autoCapitalize}
returnKeyType={this.props.returnKeyType}
placeholderTextColor={colors.dimgray}
underlineColorAndroid="transparent"
onChangeText={TextInputName => this.setState({ TextInputName })}
/>
</View>
</View>
<View style={{ flexDirection: 'column', margin: 20 }}>
<Text style={styles.textStyle}>Within</Text>
<View style={styles.sliderStyles}>
<Slider
value={this.state.value}
onValueChange={(value) => this.setState({ value })}
minimumValue={4}
maximumValue={10}
step={10}
/>
<Text>value: {this.state.value}</Text>
</View>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
textStyle: {
fontSize: 20,
color: colors.brandBlue,
},
input: {
backgroundColor: colors.white,
height: 40,
width: '80%',
marginTop: 5,
borderRadius: 4,
alignItems: 'flex-start',
justifyContent: 'flex-start',
borderWidth: 1,
borderColor: colors.light_gray,
fontSize: 20
},
sliderStyles: {
//margin: 10,
alignItems: 'stretch',
justifyContent: 'center',
},
});
export default FindDoctor;
and now the output look like this
But i want to add multiples values in slider like the image shown above
can anyone help me to add multiple values in slider

Center Text in FlatList next to Icon - React Native

I am currently trying to center the text from the FlatList.
By centering I mean I want it to be in the middle, right of each Icon.
Currently this is how is displaying, it's on the bottom. I just want it to be a little bit higher:
Here is how my component looks like:
I have tried to implement few styles, but still no success.
The thing that crossed my mind but did not try was to hard code each line and drop the loop, but I am not sure if this is right to do.
import SocialIcon from 'react-native-vector-icons/AntDesign';
import BookingIcon from 'react-native-vector-icons/FontAwesome';
import FeatherIcons from 'react-native-vector-icons/Feather';
export const bookIcon = (<BookingIcon name="pencil-square-o" size={40} color="purple" />);
export const calendarIcon = (<SocialIcon name="calendar" size={40} color="purple" />);
export const questionIcon = (<SocialIcon name="questioncircleo" size={40} color="purple" />);
export const externalLinkIcon = (<FeatherIcons name="external-link" size={40} color="purple" />);
class AboutMe extends Component {
static navigationOptions = {
title: "About Me",
}
render() {
return (
<View style={styles.container}>
<View style={styles.topBox}>
<View style={styles.circleOuter} />
<View style={styles.circle} />
</View>
<View style={styles.middleBox}>
</View>
<View style={styles.bottomBox}>
<FlatList
contentContainerStyle={styles.listItem}
data={[
{key: 'Book a free appointment', page:'Book', icon: bookIcon},
{key: 'Availability', page:'Availability', icon:calendarIcon},
{key: 'FAQ', page:'Faq', icon: questionIcon},
{key: 'Useful Links', page: 'Links', icon: externalLinkIcon},
]}
onPress={() => this.props.navigation.navigate('Book')}
renderItem={({item}) => {
return (
<TouchableHighlight onPress={() => this.props.navigation.navigate(`${item.page}`)}>
<Text >{item.icon}{item.key}</Text>
</TouchableHighlight>
)
}}
/>
</View>
</View>
);
};
};
const styles = StyleSheet.create({
container: {
flex: 1
},
topBox: {
flex:3,
backgroundColor: 'red',
justifyContent:'center',
alignItems: 'center'
},
middleBox: {
flex:1,
backgroundColor: 'yellow'
},
bottomBox: {
flex:4,
backgroundColor: 'orange',
padding: 20
},
circle: {
width: 160,
height: 160,
borderRadius: 160/2,
backgroundColor: 'green',
position: 'absolute'
},
circleOuter: {
width: 180,
height: 180,
borderRadius: 180/2,
backgroundColor: 'black'
},
listItem: {
flex:1,
justifyContent: 'center'
},
text: {
fontSize: 20,
}
});
You need to wrap the Text tag in a View/TouchableHighlight tag and then center the text tag vertically. Try this and let me know. It could be necessary that you wrap the icons in a separated image tag. if the code avode dont work means that a separeted tag is necessary so let me know!
<TouchableHighlight
style={styles.buttonsStyle}
onPress={() => this.props.navigation.navigate(`${item.page}`)}
>
<Text>{item.icon}{item.key}</Text>
</TouchableHighlight>
...
...
...
//in the styles add
buttonsStyle:{
justifyContent: 'center',
}
EDIT1
In order to wrap the icons it should be like following.. Note that you cannot use TouchableHighlight in this case. it seems to be a bug with react-native. aslo i used TouchableOpacity
renderItem={({item}) => {
return (
<TouchableOpacity
style={styles.buttonsStyle}
onPress={() => this.props.navigation.navigate(`${item.page}`)}
>
<Image style={styles.imgStyles} source={item.icon} />
<Text style={styles.mappedTextStyle}>{item.key}</Text>
</TouchableOpacity>
)
}}
styles to change/add
buttonsStyle:{
alignItems: 'center',
flexDirection:'row',
marginTop: 5,
},
imgStyles:{
width: 40,
height: 40,
marginRight: 10
},
mappedTextStyle: {
fontSize: 18,
color: 'black'
},
EDIT 2
In order to cover vector-icons lib, i have created a Expo snack for producing the desired behavior. Expo snack has also the expected solution for the problem Expo Snack

Error when back screen from navigation header : undefined is not an object (evaluating 'this.props.navigation.navigate')

I am new in react native. I am trying to close screen on button click in static navigationOptions but getting error like this
My code is here:
import React from 'react';
import { Button, View, Text ,Image } from 'react-native';
import { createStackNavigator } from 'react-navigation'; // Version can be specified in package.json
import Mylistview from './Mylistview.js'
import { TouchableOpacity } from 'react-native'
class HomeScreen extends React.Component {
static navigationOptions = {
header: null ,
};
render() {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Home Screen</Text>
<Button
title="Go to Details"
onPress={() => this.props.navigation.navigate('Details')}
/>
</View>
);
}
}
class BackClass extends React.Component {
}
class DetailsScreen extends React.Component {
static navigationOptions = {
headerLeft: //<BackClass />,
<Button
title="Go back"
onPress={() =>this.props.navigation.goBack(null)} //problem is here
/>,
headerTitle: (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center', flexDirection: 'row'
, justifyContent: 'space-between' , backgroundColor: 'black'}}>
<Button
style={{ width: 130, height: 30,flex: 1, alignItems: "center", justifyContent: 'center'}}
onPress={() => alert('This is a button!')}
title="Info change"
color="#fff000"
/>
<Button
style={{ height: 30, alignItems: "center", justifyContent: 'center'}}
onPress={() => alert('This is a button!')}
title="second"
color="#fff000"
/>
</View>
),
// headerStyle: {
// elevation: 0,
// shadowOpacity: 0
// }
headerStyle: {
height: 50,
backgroundColor: 'green',
shadowColor: 'red',
shadowRadius: 5,
shadowOpacity: 0.1,
shadowOffset: {
height: 1,
width: 0,
},
},
// titleStyle: { color: 'red' },
// left: <Text style={{color: 'red'}} onPress={() => navigation.goBack()}>LEFT</Text>,
// right: <Text style={{color: 'red'}} onPress={() => navigation.goBack()}>RIGHT</Text>,
};
render() {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Details Screen</Text>
<Button
title="Go to Details... again once"
onPress={() => this.props.navigation.push('Details')}
/>
<Button
title="Go to List"
onPress={() => this.props.navigation.push('List1')}
/>
<Button
title="Go back"
onPress={() => this.props.navigation.goBack()}
/>
</View>
);
}
}
class ListScreen extends React.Component {
render() {
return (
<Mylistview />
)
}
}
const RootStack = createStackNavigator(
{
Home: {
screen: HomeScreen,
// navigationOptions: {
// title: 'screenA',
// }
// navigationOptions: {
// header: {
// visible: false
// }
// }
},
Details: {
screen: DetailsScreen,
},
List1: {
screen: ListScreen,
},
},
{
initialRouteName: 'Home',
}
);
export default class App extends React.Component {
render() {
return <RootStack />;
}
}
//"react-navigation": "^1.0.0-beta.7"
If you want to use the navigate function from within a navigation header component you need to do it like so
static navigationOptions = ({navigation}) => ({
headerRight: <Button
title="Go back"
onPress={() => navigation.goBack()}
/>,
})

React navigation status bar alert

I'm using react-native-status-bar-alert in combination with react-navigation.
In the latest version of react-navigation there's a problem with the height.
The height of the header is too big when the alert is active.
Anyone else experienced this issue and has a solution?
I think you should use a plugin: navigationbar-react-native
First, if you use react-navigation you should hide header-bar and use custom header-bar
export const RootStack = createStackNavigator(
{
Home: {
screen: HomeComponent,
navigationOptions: {
header: null,
},
},
},
{
initialRouteName: 'Home',
}
);
1, Install package
npm i navigationbar-react-native --save
2, Using
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,Image,
View,
TouchableOpacity,
} from 'react-native';
import NavigationBar from 'navigationbar-react-native';
const ComponentLeft = () => {
return(
<View style={{ flex: 1, alignItems: 'flex-start'}} >
<TouchableOpacity style={ {justifyContent:'center', flexDirection: 'row'}}>
<Image
source={require('./img/ic_back.png')}
style={{ resizeMode: 'contain', width: 20, height: 20, alignSelf: 'center' }}
/>
<Text style={{ color: 'white', }}>Back Home</Text>
</TouchableOpacity>
</View>
);
};
const ComponentCenter = () => {
return(
<View style={{ flex: 1, }}>
<Image
source={require('./img/ic_logo.png')}
style={{resizeMode: 'contain', width: 200, height: 35, alignSelf: 'center' }}
/>
</View>
);
};
const ComponentRight = () => {
return(
<View style={{ flex: 1, alignItems: 'flex-end', }}>
<TouchableOpacity>
<Text style={{ color: 'white', }}> Right </Text>
</TouchableOpacity>
</View>
);
};
class App extends Component {
render() {
return (
<View style={styles.container}>
<NavigationBar
componentLeft = { () => {<ComponentLeft /> }
componentCenter = { () => {<ComponentCenter /> }
componentRight = { () => {<ComponentRight /> }
navigationBarStyle= {{ backgroundColor: ''#215e79'' }}
statusBarStyle = {{ barStyle: 'light-content', backgroundColor: '#215e79' }}
/>
</View>
);
}
}
Easy create custom header bar in react native