admin管理员组文章数量:1289525
This scrolling works on Ios But it Doesn't work on Android Devices.
I Set the SafeArea Height and content Container for scrollview and also set height for image and am using nativewind here. the TouchableOpaciity is Disappearing in the bottom but the scrolling is not working here is my code:
import React from "react";
import { SafeAreaView } from "react-native-safe-area-context";
import { Image, ScrollView, Text, TouchableOpacity, View } from "react-native";
import icons from "@/constants/icons";
import images from "@/constants/images";
const Auth = () => {
const handleLogin = async () => {};
return (
<SafeAreaView className="bg-white h-full">
<ScrollView
contentContainerStyle={{
height: "100%",
}}
>
<Image
source={images.onboarding}
className="w-full h-4/6"
resizeMode="contain"
/>
<View className="px-10">
<Text className="text-base text-center uppercase font-rubik text-black-200">
Welcome To Real Scout
</Text>
<Text className="text-3xl font-rubik-bold text-black-300 text-center mt-2">
Let's Get You Closer To {"\n"}
<Text className="text-primary-300">Your Ideal Home</Text>
</Text>
<Text className="text-lg font-rubik text-black-200 text-center mt-12">
Login to Real Scout with Google
</Text>
<TouchableOpacity
onPress={handleLogin}
className="bg-white shadow-md shadow-zinc-300 rounded-full w-full py-4 mt-5"
>
<View className="flex flex-row items-center justify-center">
<Image
source={icons.google}
className="w-5 h-5"
resizeMode="contain"
/>
<Text className="text-lg font-rubik-medium text-black-300 ml-2">
Continue with Google
</Text>
</View>
</TouchableOpacity>
</View>
</ScrollView>
</SafeAreaView>
);
};
export default Auth;
This scrolling works on Ios But it Doesn't work on Android Devices.
I Set the SafeArea Height and content Container for scrollview and also set height for image and am using nativewind here. the TouchableOpaciity is Disappearing in the bottom but the scrolling is not working here is my code:
import React from "react";
import { SafeAreaView } from "react-native-safe-area-context";
import { Image, ScrollView, Text, TouchableOpacity, View } from "react-native";
import icons from "@/constants/icons";
import images from "@/constants/images";
const Auth = () => {
const handleLogin = async () => {};
return (
<SafeAreaView className="bg-white h-full">
<ScrollView
contentContainerStyle={{
height: "100%",
}}
>
<Image
source={images.onboarding}
className="w-full h-4/6"
resizeMode="contain"
/>
<View className="px-10">
<Text className="text-base text-center uppercase font-rubik text-black-200">
Welcome To Real Scout
</Text>
<Text className="text-3xl font-rubik-bold text-black-300 text-center mt-2">
Let's Get You Closer To {"\n"}
<Text className="text-primary-300">Your Ideal Home</Text>
</Text>
<Text className="text-lg font-rubik text-black-200 text-center mt-12">
Login to Real Scout with Google
</Text>
<TouchableOpacity
onPress={handleLogin}
className="bg-white shadow-md shadow-zinc-300 rounded-full w-full py-4 mt-5"
>
<View className="flex flex-row items-center justify-center">
<Image
source={icons.google}
className="w-5 h-5"
resizeMode="contain"
/>
<Text className="text-lg font-rubik-medium text-black-300 ml-2">
Continue with Google
</Text>
</View>
</TouchableOpacity>
</View>
</ScrollView>
</SafeAreaView>
);
};
export default Auth;
Share
Improve this question
edited Feb 20 at 21:01
Zack Snyder
asked Feb 20 at 2:30
Zack SnyderZack Snyder
651 silver badge8 bronze badges
4
|
1 Answer
Reset to default 0Try to use flexGrow instead of flex. When setting styles for the ScrollView, avoid using flex: 1 in the contentContainerStyle. Instead, use flexGrow: 1.
This allows the content to expand and fill the available space without breaking the scrolling functionality.
At the top of that there is a fixed height (like height: '100%') on the parent component, consider removing it or setting it to a more dynamic value. Fixed heights can restrict the ability of the ScrollView to function properly.
For example:
import React from "react";
import { SafeAreaView } from "react-native-safe-area-context";
import { Image, ScrollView, Text, TouchableOpacity, View, StyleSheet } from "react-native";
import icons from "@/constants/icons";
import images from "@/constants/images";
const Auth = () => {
const handleLogin = async () => {};
return (
<SafeAreaView style={{ flex: 1, backgroundColor: 'white' }}>
<ScrollView
contentContainerStyle={styles.scrollContainer}
>
<Image
source={images.onboarding}
style={styles.onboardingImage}
resizeMode="contain"
/>
<View style={styles.contentView}>
<Text style={styles.welcomeText}>
Welcome To Real Scout
</Text>
<Text style={styles.mainText}>
Let's Get You Closer To {"\n"}
<Text style={styles.highlightedText}>Your Ideal Home</Text>
</Text>
<Text style={styles.loginText}>
Login to Real Scout with Google
</Text>
<TouchableOpacity
onPress={handleLogin}
style={styles.googleButton}
>
<View style={styles.googleButtonContent}>
<Image
source={icons.google}
style={styles.googleIcon}
resizeMode="contain"
/>
<Text style={styles.googleButtonText}>
Continue with Google
</Text>
</View>
</TouchableOpacity>
</View>
</ScrollView>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
scrollContainer: {
flexGrow: 1, // Important: Use flexGrow instead of height: '100%'
paddingBottom: 20, // Add padding to the bottom to ensure all content is accessible
},
onboardingImage: {
width: '100%',
height: undefined,
aspectRatio: 1, // Adjust as needed to maintain aspect ratio
},
contentView: {
paddingHorizontal: 10,
},
welcomeText: {
fontSize: 16,
textAlign: 'center',
textTransform: 'uppercase',
fontFamily: 'Rubik',
color: '#333', // Assuming black-200 is a dark grey
},
mainText: {
fontSize: 24,
fontFamily: 'Rubik-Bold',
color: '#222', // Assuming black-300 is a dark grey
textAlign: 'center',
marginTop: 8,
},
highlightedText: {
color: '#007BFF', // Assuming primary-300 is a blue color
},
loginText: {
fontSize: 16,
fontFamily: 'Rubik',
color: '#333', // Assuming black-200 is a dark grey
textAlign: 'center',
marginTop: 24,
},
googleButton: {
backgroundColor: 'white',
shadowColor: '#aaa',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.2,
shadowRadius: 4,
borderRadius: 999, // Large value for rounded corners
width: '100%',
paddingVertical: 12,
marginTop: 20,
},
googleButtonContent: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
},
googleIcon: {
width: 20,
height: 20,
},
googleButtonText: {
fontSize: 18,
fontFamily: 'Rubik-Medium',
color: '#222', // Assuming black-300 is a dark grey
marginLeft: 8,
},
});
export default Auth;
本文标签: androidScrollView In React Native not Scrolling when Height is set 100Stack Overflow
版权声明:本文标题:android - ScrollView In React Native not Scrolling when Height is set 100% - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741461516a2380065.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
contentContainerStyle
because it restricts the height – Eternal Dreamer Commented Feb 20 at 21:27