hi in my project I use nativeBase. I use <Button><Text>blablabla</Text></Button>
when running in android ok but when run-ios text not showing.
this is my component :
<View style={{ marginLeft: 7, flexDirection: 'column', alignItems: 'center', justifyContent: 'center' }}>
<View style={styles.btncontent}>
<Right style={{ flex: 0.2 }}>
<Image source={mapBtnLogo} style={styles.btnImage} />
</Right>
<Left style={{ flex: 0.8 }}>
<Button full transparent style={styles.btn} onPress={() => props.myProps.gotoMap([section.YPOINT, section.XPOINT])}>
<Text style={styles.btnText}>
نمایش روی نقشه
</Text>
</Button>
</Left>
</View>
</View>
and this is styles :
const styles = StyleSheet.create({
...Platform.select({
ios: {
btnImage: {
margin: 5,
marginRight: 20,
width: moderateScale(20),
height: moderateScale(20),
},
btn: {
//alignItems: 'flex-start',
width: '100%',
height: '10%',
},
btnText: {
fontFamily: 'IRANSansMobile',
fontSize: 15,
color: '#000',
},
}, android: {
btn: {
width: '100%',
height: '10%',
},
btnText: {
fontFamily: 'IRANSansMobile',
fontSize: 15,
color: '#000000'
},
btncontent: {
backgroundColor: '#59c5b8',
flexDirection: 'row-reverse',
alignItems: 'center',
borderWidth: 0.3,
borderRadius: 5,
marginLeft: 10,
width: '95%',
},
}
remove node module and install again not working.
and clear Xcode and run again but not working.
I read this post NativeBase Button doesn't show text but I don't use padding and still not showing text
You can try TouchableOpacity.
<Left style={{ flex: 0.8 }}>
<TouchableOpacity style={styles.btn} onPress={() => props.myProps.gotoMap([section.YPOINT, section.XPOINT])}>
<Text style={styles.btnText}>
نمایش روی نقشه
</Text>
</TouchableOpacity>
</Left>
I found my mistake in styling :
change height style btn in the stylesheet from 10% to 100% !!
thank
Related
I am developing iOS apps in React Native Expo.
To display the image icon and placeholder in the Input column, I set it to Image icon and TextInput in the View.
When using KeyboardAvoidingView, the keyboard scrolls to the bottom of TextInput as shown in the attached image (1), but does anyone know if it is possible to scroll to the bottom of the description of the input field as shown in image (2)?
Image(1)
Image(2)
The article is based on the following.
https://reactnative.dev/docs/keyboardavoidingview
Parent function code.
<KeyboardAvoidingView behavior="padding" style={styles.containerStyle}>
<SafeAreaView style={styles.containerStyle}>
<ScrollView style={styles.containerStyle}>
<View style={styles.headContainerStyle}></View>
<View style={styles.mainContainerStyle}></View>
<View style={styles.headMessageContainerStyle}>
<Text style={styles.headMessageTextStyle}>Sign Up</Text>
</View>
{/* Email */}
<MailForm
inputAccessoryViewID={inputAccessoryViewID}
isCorrectMail={isCorrectMail}
setIsCorrectMail={setIsCorrectMail}
/>
{/* Password */}
<PasswordForm
inputAccessoryViewID={inputAccessoryViewID}
isCorrectPassewordSymbol={isCorrectPassewordSymbol}
setIsCorrectPassewordSymbol={setIsCorrectPassewordSymbol}
isCorrectPassewordStringCount={isCorrectPassewordStringCount}
setIsCorrectPassewordStringCount={setIsCorrectPassewordStringCount}
/>
{/* UserId */}
<UserIdForm
inputAccessoryViewID={inputAccessoryViewID}
isCorrectUserIdSymbol={isCorrectUserIdSymbol}
setIsCorrectUserIdSymbol={setIsCorrectUserIdSymbol}
isCorrectUserIdStringCount={isCorrectUserIdStringCount}
setIsCorrectUserIdStringCount={setIsCorrectUserIdStringCount}
isAvailableUserId={isAvailableUserId}
setIsAvailableUserId={setIsAvailableUserId}
/>
{/* Screen Bottom */}
<View style={styles.bottomStyle}>
{isCorrectMail && isCorrectPassewordSymbol && isCorrectPassewordStringCount && isCorrectUserIdSymbol && isCorrectUserIdStringCount && isAvailableUserId ?
(
<TouchableOpacity
style={styles.buttonContainerStyle}>
<Text style={styles.buttonTextStyle}>Sign Up</Text>
</TouchableOpacity>
) : (
<TouchableOpacity
style={[styles.buttonContainerStyle, styles.buttonContainerInvalidStyle]}
onPress={() => navigation.navigate('SignUp')}>
<Text style={styles.buttonTextStyle}>Sign Up</Text>
</TouchableOpacity>
)}
<View style={styles.toLoginStyle}>
<Text style={styles.toLoginTextStyle}>Do you have an account?</Text>
<Text style={[styles.toLoginTextStyle, styles.toLoginTextLinkStyle]}>Login here</Text>
</View>
</View>
</ScrollView>
</SafeAreaView>
</KeyboardAvoidingView>
The code for the <UserId/> component, which we want to support scrolling for this time.
<View>
<View style={styles.searchBoxStyle}>
<View style={styles.searchWrapperStyle}>
<Pressable style={styles.searchContainerStyle} onPress={() => textInputUserId.focus()}>
<Text style={styles.searchTitleStyle}>UserId</Text>
{/* <KeyboardAvoidingView behavior="padding"> */}
<View style={defaultUserIdBorderColor ? isCorrectUserIdSymbol && isCorrectUserIdStringCount ? styles.searchViewStyle : [styles.searchViewStyle, styles.inputIncorrectBorderColorStyle]: styles.searchViewStyle}>
<Image source={require("../../../assets/profile.png")} style={styles.searchIconStyle}/>
{/* <KeyboardAvoidingView behavior="padding"> */}
<TextInput
onChangeText={onChangeUserIdText}
style={styles.searchContentStyle}
value={userIdText}
placeholder="test1234"
inputAccessoryViewID={inputAccessoryViewID}
ref={(input) => textInputUserId = input}
autoCapitalize="none"
maxLength={100}
textContentType="username"
onFocus={() => {
…
}}
onEndEditing={() => {
…
}}
/>
</View>
</Pressable>
</View>
</View>
{/* UserId Description */}
{displayUserIdDescription ? !isCorrectUserIdSymbol || !isCorrectUserIdStringCount || !isAvailableUserId ? (
<View style={styles.descriptionBoxStyle}>
<View style={styles.descriptionWrapperStyle}>
<View style={styles.descriptionContainerStyle}>
{!defaultDisplayUserIcons ? isCorrectUserIdSymbol ? <Image source={require("../../../assets/correct.png")} style={styles.descriptionIconStyle}/>: <Image source={require("../../../assets/incorrect.png")} style={styles.descriptionIconStyle}/>: null}
<Text style={styles.descriptionTextStyle}>Half-width alphanumeric characters only.</Text>
</View>
<View style={styles.descriptionContainerStyle}>
{!defaultDisplayUserIcons ? isCorrectUserIdStringCount ? <Image source={require("../../../assets/correct.png")} style={styles.descriptionIconStyle}/>: <Image source={require("../../../assets/incorrect.png")} style={styles.descriptionIconStyle}/>: null}
<Text style={styles.descriptionTextStyle} >More than 4 words and less than 100 words.</Text>
</View>
<View style={styles.descriptionContainerStyle}>
{!defaultDisplayUserIcons ? isAvailableUserId ? <Image source={require("../../../assets/correct.png")} style={styles.descriptionIconStyle}/>: <Image source={require("../../../assets/incorrect.png")} style={styles.descriptionIconStyle}/>: null}
<Text style={styles.descriptionTextStyle} >Available.</Text>
</View>
</View>
</View>
) : null: null}
</View>
Style sheet code.
import { StyleSheet } from 'react-native';
export const styles = StyleSheet.create({
containerStyle: {
flex: 1,
backgroundColor: "#1B1C56",
},
headContainerStyle: {
width: "100%",
height: "10%",
height: 40,
backgroundColor: "#1B1C56",
},
headMessageContainerStyle: {
backgroundColor: "#feffff",
alignItems: 'center',
},
headMessageTextStyle: {
fontSize: 50,
fontFamily: "AlfaSlabOne_400Regular",
color: "#1B1C56",
marginBottom: 32,
},
mainContainerStyle: {
width: "100%",
height: "15%",
backgroundColor: "#feffff",
borderTopLeftRadius: 50,
alignItems: 'center',
},
searchBoxStyle: {
flex: 1,
backgroundColor: "#feffff",
},
searchWrapperStyle: {
flex: 1,
alignItems: "center",
paddingBottom: 10,
},
searchContainerStyle: {
},
searchTitleStyle: {
fontFamily: "ABeeZee_400Regular_Italic",
color: "#262626",
marginBottom: 5,
},
searchIconStyle: {
width: 24,
height: 24,
marginRight: 10,
marginLeft: 10,
},
searchViewStyle: {
flexDirection: 'row',
alignItems: 'center',
backgroundColor: '#F6F7FB',
borderWidth: 0.5,
height: 60,
borderRadius: 5,
width: 300,
borderColor: "#F6F7FB",
},
searchContentStyle: {
flex: 1
},
inputIncorrectBorderColorStyle:{
borderWidth: 2,
borderColor: "#ED195E",
},
completeBoxStyle: {
width: 60,
alignItems: "center",
padding: 10,
},
completeTextStyle: {
fontSize: 18,
fontWeight: "bold",
color: "hsl(210, 100%, 60%)"
},
passwordIconStyle: {
marginRight: 10
},
descriptionBoxStyle:{
display: "flex",
alignItems: "center",
backgroundColor: "#feffff",
paddingBottom: 10,
},
descriptionWrapperStyle: {
},
descriptionContainerStyle: {
flexDirection: "row",
width: 300,
},
descriptionTextStyle: {
color: "#262626",
fontSize: 12,
overflow: "visible"
},
descriptionIconStyle:{
marginRight: 10,
width: 12,
height: 12,
},
bottomStyle: {
display: "flex",
alignItems: "center",
height: "100%",
backgroundColor: "#feffff",
},
buttonContainerStyle: {
alignItems: "center",
justifyContent: "center",
backgroundColor: "#1B1C56",
width: 300,
height: 60,
borderRadius: 10,
fontSize: 18,
},
buttonContainerInvalidStyle:{
backgroundColor: "#C5C5C7",
},
buttonTextStyle: {
color: "#feffff",
fontFamily: "ABeeZee_400Regular_Italic",
},
toLoginStyle: {
marginTop: 10,
height: "5%",
flexDirection: "row"
},
toLoginTextStyle: {
fontFamily: "ABeeZee_400Regular_Italic",
},
toLoginTextLinkStyle: {
color: "#ED195E",
marginLeft: 10,
},
});
Swapped the positions of KeyboardAvoidingView, SafeAreaView and ScrollView. I have tried to set the keyboardVerticalOffset and the keyboardVerticalOffset, but each had its own problems, and the current code was the closest to the ideal.
I am trying to avoid the keyboard over the form, according to React Native documentation, I should be using KeyboardAwareScrollView component. the instructions are fairly simple, but I cant make it work. Am I missing anything?
return (
<KeyboardAvoidingView
behavior={Platform.OS === "ios" ? "padding" : "height"}
style={{ flex: 1 }}
>
<View style={styles.card}>
<View style={styles.container}>
<Options setIpt={setIpt} />
<View style={styles.input}>
<ShowIpt /> // form input here
</View>
<Button
title="Create"
color="#841584"
accessibilityLabel="Create"
onPress={() =>
navigation.navigate("Result", {
ipt: ipt,
})
}
/>
</View>
</View>
</KeyboardAvoidingView>
);
const styles = StyleSheet.create({
container: {
margin: 10,
},
card: {
backgroundColor: "#F2F2F2",
margin: 10,
marginTop: 20,
borderRadius: 10,
height: "90%",
display: "flex",
},
input: {
backgroundColor: "#FFF",
height: 250,
alignItems: "center",
justifyContent: "center",
borderRadius: 10,
marginTop: 20,
marginBottom: 20,
},
});
Use automaticallyAdjustContentInsets and contentContainerStyle properties and change your style like below.
<KeyboardAvoidingView
automaticallyAdjustContentInsets={false}
behavior={null}
contentContainerStyle={{ flex: 1 }}
style={{
backgroundColor: 'backgroundColor',
flex: 1,
height: '100%',
}}
>
</KeyboardAvoidingView>
I've seen the same question many times, but none of the solutions I found worked for me.
return part
<View style={styles.root}>
<ScrollView contentContainerStyle={{ flexGrow: 1 }} scrollEnabled={true}>
<View style={styles.dpArea}>
<Image
source={{
uri: "URI GOES HERE",
}}
style={{ width: "100%", height: "100%" }}
resizeMode="contain"
/>
</View>
<View style={styles.nameArea}>
<View style={{ flex: 8, alignItems: "center" }}>
<Text style={styles.nameText}> {nameUpper}</Text>
</View>
<View style={{ flex: 2, paddingLeft: 10 }}>
<MaterialIcons name="edit" size={24} color="gray" />
</View>
</View>
<View style={styles.emailArea}>
<Text
style={{
fontFamily: "Reg",
fontSize: 12,
color: "gray",
marginRight: 4,
}}
>
Logged in using
</Text>
<Text style={{ fontFamily: "Reg", fontSize: 12 }}>{email}</Text>
</View>
<View style={styles.statsArea}>
<StatsContainer text="STAT 1" number="41" />
<StatsContainer text="STAT 2" number="93" />
</View>
<View style={styles.feedbackArea}>
<Text style={{ fontFamily: "Bold", fontSize: 12, color: "gray" }}>
Send feedbacks, feature requests or report bugs:
</Text>
<FeedbackArea content={feedback} />
</View>
<View style={styles.logoutArea}>
<GenButton content="LOGOUT" />
<DeleteAcButton content="DELETE ACCOUNT" />
</View>
<View style={styles.madeByArea}>
<Text style={styles.madebyText}>Developed by:</Text>
</View>
</ScrollView>
</View>
StyleSheet :
root: {
flex: 1,
},
dpArea: {
height: "30%",
marginTop: 20,
overflow: "hidden",
alignItems: "center",
justifyContent: "center",
},
nameArea: {
height: "10%",
flexDirection: "row",
justifyContent: "space-around",
alignItems: "center",
},
emailArea: { height: "10%", flexDirection: "row", justifyContent: "center" },
statsArea: { flexDirection: "row", height: "20%", marginBottom: "10%" },
feedbackArea: { height: "20%", marginHorizontal: "5%" },
logoutArea: {
width: "100%",
justifyContent: "space-around",
alignItems: "center",
height: "30%",
marginVertical: "5%",
},
madeByArea: {
height: "10%",
justifyContent: "flex-end",
alignItems: "center",
marginBottom: 3,
},
madebyText: {
fontFamily: "Reg",
fontSize: 12,
color: "gray",
},
nameText: {
fontFamily: "Bold",
fontSize: 30,
},
What I've tried: making scrollview the parent component, wrapping scrollview in a root view, flex & flexGrow=1 in contentContainerStyle, flex & flexGrow=1 in ScrollView style parameter.
What I've observed is, if I change any text's font size to say 300, then scroll works but not all components are rendered, however, with normal font size, there's no scroll even though the page exceeds the screen size.
I presume it's due to the way stylesheet is configured, but am unable to locate the error.
In my screen, I need to split the text into column view and need to align the right side text with the left side text. also, need to show the whole text line by line. Tested with giving some height, width, position: absolute but didn't work. Any idea how to solve this?
I'll post my current code and screenshot for your ref.
Many thanks for your help
<View style={styles.twoCol}>
<View style={styles.leftField}>
<Text style={styles.leftFieldTitle}>Location:</Text>
</View>
<View style={styles.locationRightSide}>
<Text style={styles.rightFieldTitle}>{location}</Text>
</View>
</View>
const styles = StyleSheet.create({
twoCol: {
alignItems: 'center',
flexDirection: 'row',
marginTop: 25,
},
leftField: {
alignItems: 'flex-end',
width: '25%',
},
leftFieldTitle: {
fontWeight: '700',
color: 'black'
},
},
locationRightSide: {
width: '70%',
alignItems: 'flex-start',
paddingLeft: 10
},
rightFieldTitle: {
fontSize: RF(2.8),
color: 'black'
},
)}
Problem solved!!! Thanks everyone!
<View style={{
padding: 10,
flexDirection: "row",
marginLeft: 10,
marginRight: 5,
marginTop: 5,
marginBottom: 3,
justifyContent: "flex-start",
width: '95%',
}} >
<View style={{
position: 'absolute',
marginTop: 10
}}>
<Text style={styles.leftFieldTitle}>Location:</Text>
</View>
<View style={{ marginLeft: '26%' }}>
<Text style={styles.rightFieldTitle}>{location}</Text>
</View>
</View>
I'm building a react-native app and I'm having a problem styling the components.
For some reason when I add a margin to one of the components the main component doesn't occupy the full height of the screen even though is "flex:1".
In this example the problem happens with the back button, if I use padding it works fine but I need to use margin so the user doesn't press the wrong component by mistake.
And the same problem happens in the rest of the app with different components that have a margin property.
Main component
body: {
flex: 1,
backgroundColor: 'green'
},
subHeader: {
backgroundColor: '#f4f4f4',
height: 95,
flexDirection: 'row'
},
vericalBar: {
width: 9
},
subHeaderDescription: {
flex: 1,
justifyContent: 'center',
marginLeft: 16
},
subHeaderLocation: {
color: '#2d2d2d',
fontSize: 14,
marginBottom: 10
},
subHeaderText: {
color: '#2d2d2d',
fontSize: 20
},
subHeaderStatus: {
alignItems: 'center',
justifyContent: 'center',
marginRight: 18
},
listDescription: {
backgroundColor: 'red',
flexGrow: 1,
paddingTop: 16,
paddingLeft: 20
},
taskDescription: {
color: '#2d2d2d',
fontSize: 16
}
<View style={localStyles.body}>
<Header navigation={this.props.navigation} />
<View style={localStyles.subHeader}>
<View style={[localStyles.vericalBar, { backgroundColor: task.color }]} />
<View style={localStyles.subHeaderDescription}>
<Text style={localStyles.subHeaderLocation}>{location.name}</Text>
<Text style={localStyles.subHeaderText}>{task.name}</Text>
</View>
{iconSelector(task)}
</View>
<BackButton navigation={this.props.navigation} />
<View style={localStyles.listDescription}>
<Text style={localStyles.taskDescription}>{task.description}</Text>
</View>
{returnStatus(task)}
<ReportIssueButton navigation={this.props.navigation} />
<Footer navigation={this.props.navigation} />
</View>
Back Button
<TouchableWithoutFeedback onPress={() => navigation.goBack()}>
<View style={localSytles.container}>
<Image style={{ width: 14, height: 14 }} source={require('../../Images/Back.png')} />
<Text style={localSytles.buttonText}>Back</Text>
</View>
</TouchableWithoutFeedback>
container: {
flexDirection: 'row',
height: 40,
paddingLeft: 20,
alignItems: 'center',
backgroundColor: 'blue'
},
buttonText: {
color: '#2d2d2d',
fontSize: 14,
marginLeft: 10
}
I've found the problem, the container "listDescription" had a "paddingTop: 16"
by removing that property it allowed the container to push the rest of the containers down.