React Native border width issue on iOS - ios

I am new to React Native and also have little to no experience with React JS.
I have an app with screens that are built of ScrollView component containing Views of different heights. If I open the app on iPhone 7, bottom borders of these View components have bigger width the higher the View component is (the more content it contains). These Views have very simple css as below:
screenSection: {
borderBottomWidth: 1,
borderBottomColor: '#333438',
marginBottom: 48,
},
Ive also tried adding / PixeslRatio.get() after borderBottomWidth but it didnt help.
This happens only on physical Iphone devices, not in Iphone Simulator on Mac or even on Android devices.
Anyone have a clue what can be causing this? Thanks in advance!
Code sample:
<ScrollView>
<View style={{borderBottomWidth: 1, borderBottomColor: '#333438', marginBottom: 48,}}>
<Text style={{fontSize: 20, marginHorizontal: 24}}>Section1 Title</Text>
<View style={{marginHorizontal: 24}}>
<View style={{borderBottomWidth: 1, borderBottomColor: colors.darkGray, paddingBottom: 10,}}>
<Text>SubSection Title</Text>
</View>
<View style={{paddingVertical: 32, width: '100%'}}>
<Text>Some content (does not have to be text)</Text>
</View>
</View>
</View>
<View style={{borderBottomWidth: 1, borderBottomColor: '#333438', marginBottom: 48,}} >
<Text style={{fontSize: 20, marginHorizontal: 24}}>Section2 Title</Text>
<View style={{marginHorizontal: 24}}>
<View style={{borderBottomWidth: 1, borderBottomColor: colors.darkGray, paddingBottom: 10,}}>
<Text>SubSection1 Title</Text>
</View>
<View style={{paddingVertical: 32, width: '100%'}}>
<Text>Some content (does not have to be text)</Text>
</View>
</View>
<View style={{marginHorizontal: 24}}>
<View style={{borderBottomWidth: 1, borderBottomColor: colors.darkGray, paddingBottom: 10,}}>
<Text>SubSection2 Title</Text>
</View>
<View style={{paddingVertical: 32, width: '100%'}}>
<Text>Some content (does not have to be text)</Text>
</View>
</View>
</View>
The second Section will have thicker borderBottom because it has 2 subsections

Related

React Native Flatlist shows a blank space in tvOS

I'm trying to show a flatList in tvOS and when the flatlist is rendered it shows unwanted space at the top of the rendered items inside the flatlist. This issue is not happening in Android TV or Fire TV.
My code :
<SafeAreaView
style={{
flex: 1,
backgroundColor: Colors.APP_BACKGROUND,
flexDirection: 'row',
}}>
<View style={{width: '27%'}}>
<View
style={[{flex: 1, marginLeft: Platform.OS === 'android' ? '10%' : '5%', marginRight: '10%', marginTop: '10%'}]}>
<Text
style={[
{
fontSize: FontSize.large,
color: Colors.WHITE,
fontFamily: FontFamily.bold,
marginBottom: '5%',
paddingHorizontal: ms(10),
marginLeft: Platform.OS === 'android' ? ms(5) : ms(2),
},
]}>
Settings
</Text>
<FlatList
data={pages}
renderItem={({item, index}) => renderSettingItem(item, index)}
removeClippedSubviews={false}
/>
</View>
</View>
<View
style={{
backgroundColor: Colors.SEPARATOR_SETTING_PAGE,
width: 3,
marginTop: '2%',
height: '60%',
}}
/>
<View style={{width: '73%'}}>
<SettingPageComponent page={page} />
</View>
</SafeAreaView>
I don't know what I did wrong. I'd really appreciate some help. Thanks !

How to extend image across width of screen?

I am attempting to make the images scroll horizontally. I downloaded some UI, and added ScrollView horizontal. But instead of it looking the same just with the ability to scroll horizontally, it shrank the image (and also gave it the ability to scroll horizontally). What should I change to make it stretch all the way across (still with the padding)?
Posts.js
import React from "react";
import {
View,
Text,
Image,
ImagBackground,
ImageBackground,
} from "react-native";
import Icon from "#expo/vector-icons/Entypo";
import { ScrollView, TouchableOpacity } from "react-native-gesture-handler";
export default class Posts extends React.Component {
state = {
liked: false,
};
onLike = () => {
this.setState({ liked: !this.state.liked });
};
render() {
const { name, profile, photo, onPress } = this.props;
return (
<View>
<View
style={{
flexDirection: "row",
paddingTop: 25,
alignItems: "center",
}}
>
<View style={{ width: "20%" }}>
<Image
source={profile}
style={{
width: 45,
height: 45,
borderRadius: 13,
}}
/>
</View>
<View
style={{
width: "60%",
}}
>
<Text
style={{
fontFamily: "Bold",
fontSize: 14,
color: "#044244",
}}
>
{name}
</Text>
<Text
style={{
fontFamily: "Medium",
fontSize: 12,
color: "#9ca1a2",
}}
>
2 mins ago
</Text>
</View>
<View
style={{
width: "20%",
alignItems: "flex-end",
}}
>
<Icon name="sound-mix" color="#044244" size={20} />
</View>
</View>
<View
style={{
flexDirection: "row",
width: "100%",
paddingTop: 20,
}}
>
<ScrollView horizontal>
<ImageBackground
source={photo}
style={{
width: "100%",
height: 220,
}}
imageStyle={{
borderRadius: 30,
}}
>
<View
style={{
height: "100%",
flexDirection: "row",
alignItems: "flex-end",
justifyContent: "flex-end",
}}
>
<TouchableOpacity
onPress={onPress}
style={{
marginBottom: 20,
borderRadius: 5,
padding: 5,
backgroundColor: "#e8e8e8",
}}
>
<Icon name="forward" color="#044244" size={20} />
</TouchableOpacity>
<TouchableOpacity
onPress={this.onLike}
style={{
marginBottom: 20,
borderRadius: 5,
padding: 5,
backgroundColor: "#e8e8e8",
marginLeft: 10,
marginRight: 20,
}}
>
<Icon
name={
this.state.liked === true ? "heart" : "heart-outlined"
}
color={this.state.liked === true ? "red" : "#044244"}
size={20}
/>
</TouchableOpacity>
</View>
</ImageBackground>
</ScrollView>
</View>
</View>
);
}
}
Here's me adding more words because the post doesn't have enough words on it's own. When will they finally remove this pointless feature? I feel as if I clearly expressed my question with the few words I used.
I believe your issue is with your View wrapping your ScrollView. There is no need of wrapping ScrollView, that too in row, due to which the remaining space is visible. Just define the ScrollView, and it would work just fine. Give a width of 100% to your ScrollView though.
For any sort of styling to the parent for the ScrollView, do it inside the ScrollView itself, like the way I did in the code.
Please note ScrollView accepts a list of child items, currently I see only a single item, if you've intentionally added this one, then it is fine, else, you need to refactor your code surely. This won't work out for you.
// PLEASE NOTE --> Commented Lines should be removed, and
// only ScrollView should be considered with the styling specified
// <View
// style={{
// flexDirection: "row",
// width: "100%",
// paddingTop: 20,
// }}
// >
<ScrollView horizontal
style={{
width: '100%',
marginTop: 20,
paddingLeft: 16,
paddingRight: 6
}}>
<ImageBackground
source={photo}
style={{
width: "100%",
height: 220,
marginRight: 10
}}
imageStyle={{
borderRadius: 30,
}}
>
<View
style={{
height: "100%",
flexDirection: "row",
alignItems: "flex-end",
justifyContent: "flex-end",
}}
>
<TouchableOpacity
onPress={onPress}
style={{
marginBottom: 20,
borderRadius: 5,
padding: 5,
backgroundColor: "#e8e8e8",
}}
>
<Icon name="forward" color="#044244" size={20} />
</TouchableOpacity>
<TouchableOpacity
onPress={this.onLike}
style={{
marginBottom: 20,
borderRadius: 5,
padding: 5,
backgroundColor: "#e8e8e8",
marginLeft: 10,
marginRight: 20,
}}
>
<Icon
name={
this.state.liked === true ? "heart" : "heart-outlined"
}
color={this.state.liked === true ? "red" : "#044244"}
size={20}
/>
</TouchableOpacity>
</View>
</ImageBackground>
</ScrollView>
// </View>

TouchableOpacity in absolute position view on ios

I'm building the react native project.
This code works well on Android but doesn't work well on ios.
if I touch the first half of the button, it works, but touch doesn't work on the end of the button.
<View style={{backgroundColor: 'red', position: 'absolute', bottom: 0, alignSelf: 'center', width: 300}}>
<TouchableOpacity onPress={()=>{console.log('clicked!');}>
<View style={{flex: 1, backgroundColor: 'blue', width: 300}}>
<Text style={{flex: 1, backgroundColor: 'green', width: '100%', textAlign: 'center'}}>
Click Me!
</Text>
</View>
</TouchableOpacity>
</View>

How can I display more elements in a react native View?

I would like to show on the homepage of my react native app , a view that in turn shows a text element and an icon, then below these 2 I would like to show the amazon logo. I tried but it only shows me the logo.
export default class Header extends Component {
render() {
return (
<View style={{ flex: 1, flexDirection: 'row' }}>
<Text style={styles.Title}>Acquista!</Text>
<Ionicons name="ios-contact" size={42} color='red' style={{ marginTop:
65, marginLeft: 210 }} />
</View> ,
<Logo></Logo>
);
}
}
class Logo extends Component {
render() {
return (
<View>
<Image
style={{ height: 200, width: 200, marginTop: 150 }}
source={require('./assets/images/amazon.jpg')}
/>
</View>
);
}
}
Wrap everything into a View
return (
<View style={{ flex: 1 }}>
<View style={{ flex: 1, flexDirection: 'row' }}>
<Text style={styles.Title}>Acquista!</Text>
<Ionicons name="ios-contact" size={42} color='red' style={{ marginTop: 65, marginLeft: 210 }} />
</View>
<Logo />
</View>
)

React Native: Flex for ScrollView doesn't work

I have a simple View which has two children, another View and a ScrollView. The ScrollView should be 5x higher than the View on the same level, using flexbox.
<View style={{ flex: 1}}>
<View style={{flex: 1, backgroundColor: 'powderblue'}}>
<Text>Add new stuff</Text>
<Button title="Browse Gallery" onPress={ openGallery } />
</View>
<ScrollView style={{flex: 5, backgroundColor: 'skyblue'}}>
<Text style={{ fontSize: 100}}>Scroll me plz</Text>
<Text style={{ fontSize: 100}}>Scroll me plz</Text>
</ScrollView>
</View>
So I simply added flex:1 and flex:5 to the children Views, but the in the rendered view both of them fit exactly to half of the screen. It looks as if the two flex attributes are ignored...
Btw, using a second View instead of the ScrollView works just fine!
Any ideas how to achieve the 1:5 ratio with a ScrollView?
ScrollView is a component which doesn't inherit the use of flex. What you want to do is wrap the ScrollView in a View which will create the flex ratio you desire.
<View style={{flex: 1}}>
<View style={{flex: 1, backgroundColor: 'powderblue'}}>
<Text>Add new stuff</Text>
<Button title="Browse Gallery" onPress={ openGallery } />
</View>
<View style={{flex: 5}}>
<ScrollView style={{backgroundColor: 'skyblue'}}>
<Text style={{ fontSize: 100}}>Scroll me plz</Text>
<Text style={{ fontSize: 100}}>Scroll me plz</Text>
</ScrollView>
</View>
</View>
To achieve 1:5 screen ratio, having child component View and ScrollView with respect to parent View, you can code it in following manner:
<View style={{ flex: 1}}>
<View style={{flex: 1/5, backgroundColor: 'powderblue'}}>
<Text>Add new stuff</Text>
<Button title="Browse Gallery" onPress={ openGallery } />
</View>
<ScrollView style={{flex: 4/5, backgroundColor: 'skyblue'}}>
<Text style={{ fontSize: 100}}>Scroll me plz</Text>
<Text style={{ fontSize: 100}}>Scroll me plz</Text>
<Text style={{ fontSize: 100}}>Scroll me plz</Text>
</ScrollView>
</View>

Resources