Style does not work stably when using Expo and NativeBase - react-native

I developing my app with Expo and NativeBase.
Now this time, I would like you to help me with this weird Style problem.
Environment
"dependencies": {
"#react-navigation/bottom-tabs": "^6.3.1",
"#react-navigation/native": "^6.0.10",
"#react-navigation/native-stack": "^6.6.1",
"babel-plugin-dotenv-import": "^2.2.0",
"expo": "~44.0.0",
"expo-location": "~14.0.1",
"expo-permissions": "~13.1.0",
"expo-status-bar": "~1.2.0",
"native-base": "^3.3.11",
"prettier": "^2.6.2",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-native": "0.64.3",
"react-native-maps": "0.29.4",
"react-native-safe-area-context": "3.3.2",
"react-native-screens": "~3.10.1",
"react-native-svg": "12.1.1",
"react-native-web": "0.17.1",
"tailwind-rn": "^4.2.0",
"tailwindcss": "^3.0.23"
},
Example
As I wrote above, Style dose not work stably for any reasons and it's the problem.
I will show you my example.
Expected Style
This picture is my expected view in this case.
What I want do is placing the white box that has texts and buttons inside on the center of the MapView.
Actual Style
This picture is the weird problem.
Style works well and is displayed like the above picture sometimes, but the other times, like the below picture, it does not work.
The weird thing is that every time I reload the app without editing my code, Style's appearance sometimes changes. This is the meaning of "Style does not work stably".
NOTE: This picture looks different a bit from the above picture like the button color. Please don't care about details because this is just a developing view.
What I did for fixing the problem
Clear cache and reload the app
Stop using my custom theme
These does not fix the problem.
code
Here is my code.
WordBox is called by HomePresenter.
When onPress is emitted, WordBox shows.
I'm not familiar with React Native and Expo very much, so I first faced this problem and am really troubled.
My explanation must be complex because I am not used to use English, but if it is alright with you, please tell me how to fix it.
Thank you.
export const WordBox = (isShow: boolean): JSX.Element | null => {
if (!isShow) {
return null
} else {
return (
<View width="full" height="full">
<Center width="full" height="full">
<Box
width={sizes.Box.width}
height={sizes.Box.height}
backgroundColor={colors.Base.White}
borderRadius="3xl"
shadow="7"
>
<Text mt="4" fontSize="3xl" fontWeight="bold" textAlign="center">
Set a new marker here?
</Text>
<Button
fontWeight="bold"
fontSize="2xl"
borderRadius="3xl"
width="28"
height="10"
>
Yes
</Button>
<Button
fontWeight="bold"
fontSize="2xl"
borderRadius="3xl"
width="28"
height="10"
>
No
</Button>
</Box>
</Center>
</View>
)
}
}
Additional Information(Without NativeBase code)
I styled my app again without NativeBase following great Abe's advise.
This issue still happens.
The minor appearance is different from above pictures a bit, but the view changes when reloading my app or rerunning it like these two pictures because Style doesn't work well.
Here is my code without using NativeBase but using tailwind-rn instead.
export const WordBox = (isShow: boolean): JSX.Element | null => {
const tailwind = useTailwind()
return (
<View style={tailwind('m-auto bg-white rounded-3xl h-1/6 w-10/12')}>
<Text style={tailwind('mt-2 text-2xl font-bold text-center')}>
Set a marker here?
</Text>
<View style={tailwind('mt-4 gap-x-2 flex-row justify-center')}>
<Pressable style={tailwind('rounded-3xl w-7 h-2.5 bg-emerald-600')}>
<Text style={tailwind('font-bold text-base')}>Yes</Text>
</Pressable>
<Pressable style={tailwind('rounded-3xl w-7 h-2.5 bg-emerald-600')}>
<Text style={tailwind('font-bold text-base')}>No</Text>
</Pressable>
</View>
</View>
)
}
Additional Information(Where WordBox is called)
WordBox is called inside MapView component which is wrapped by HomePresenter.
newmarker is called when I press on the screen, so new marker is not related to this problem, I think.
export const HomePresenter: FC<HomeProps> = ({
loading,
location,
newMarker,
showAddModal,
onPress,
}) => {
const tailwind = useTailwind()
return (
<View>
{loading ? (
<View style={tailwind('text-center justify-center')}>
<Text style={tailwind('font-bold text-2xl')}>Loading</Text>
</View>
) : (
<>
<MapView
key="mapview"
provider={PROVIDER_GOOGLE}
showsUserLocation={true}
showsMyLocationButton={true}
style={tailwind('h-full w-full')}
region={location}
onPress={(e: MapEvent) => {
onPress(e)
}}
>
{newMarker && newMarker}
<WordBox /> // WordBox is called HERE
</MapView>
</>
)}
</View>
)
// }
}

I resolved this problem thanks to #Abe.
The source of this issue is placing Modal inside MapView component.
I should've placed my modal underneath MapView. In fact, this is written in the react-native-maps Docs
I hope those who use react-native-maps do not make the same mistakes.

Related

How to avoid keyboard pushing the entire layout upward in React Native v0.70.5 on Android

I am using:
"expo": "~47.0.12",
"react": "18.1.0",
"react-dom": "18.1.0",
"react-native": "0.70.5",
"softwareKeyboardLayoutMode": "resize",
I have tried KeyboardAvoidingView and KeyboardAwareScrollView but it still not working.
<KeyboardAvoidingView enabled={true} behavior="padding" style={{ flex: 1 }} >
<View style={signupStyles.container} >
<SignUpheader />
<InputArea />
<PasswordInput />
<View/>
</KeyboardAvoidingView>
Before
After
I want it to be like this but without using "softwareKeyboardLayoutMode": "pan" as it creating problem in another screen

Why react-native-reanimated-carousel does not allow manual swiping?

I am using react-native-reanimated-carousel ^2.5.0 and it does show photos as it should but when I try to swipe left or right it does not do anything, it does not scroll nor shows any errors.
Here are dependencies related to it:
"react-native-reanimated": "^2.4.1",
"react-native-reanimated-carousel": "^2.5.0",
"react-native-gesture-handler": "^2.4.2",
and here is the Carousel code:
<Carousel
width={windowWidth * 1.1}
data={newImgArr}
windowSize={10}
loop={true}
mode={'parallax'}
autoPlay={false}
renderItem={({ item }, index) => {
return (
<FastImage
source={{
uri: item,
priority: FastImage.priority.high,
cache: FastImage.cacheControl.immutable,
}}
style={{ flex: 1 }}
resizeMode={FastImage.resizeMode.cover}
/>
);
}}
/>
I would really appreciate some help here!
This problem was already mentioned in a resolved issue.
You just have to wrap your Carousel in GestureHandlerRootView.
export default function App() {
return <GestureHandlerRootView>{/* content */}</GestureHandlerRootView>;
}

Why does tabBarIcon not navigate to my component in my Tab.Screen?

When building a custom Tab.Screen I've tried to pass a custom tabBarIcon. While the icon renders it will not navigate to the component TestScreen. In the docs for tabBarIcon my understanding the Tab.Screen should be written as:
<Tab.Screen
name={routes.FOO}
component={TestScreen}
options={{
tabBarIcon: ({ focused }) => (
<TouchableOpacity>
<View style={styles.actionButton}>
<Image source={plus} style={styles.imageIcon} />
</View>
</TouchableOpacity>
),
}}
/>
When I omit the options:
<Tab.Screen
name={routes.FOO}
component={TestScreen}
/>
the onClick renders the component when clicked. When I read the docs for Options for screens it mentions screenOptions should be passed on the Navigator or Group. I tried to see if I could find a similar Q&A:
React native react-navigation tabBarIcon does not display
Why Is My Component not Rendering Within my Tab.Screen?
but I was unable to see where my error is.
My current dependencies:
"dependencies": {
"#react-navigation/bottom-tabs": "^6.0.5",
"#react-navigation/native": "^6.0.2",
"expo": "~42.0.1",
"expo-status-bar": "~1.0.4",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-42.0.0.tar.gz",
"react-native-gesture-handler": "^1.10.3",
"react-native-safe-area-context": "3.2.0",
"react-native-screens": "~3.4.0",
"react-native-web": "~0.13.12"
},
"devDependencies": {
"#babel/core": "^7.9.0"
},
How can I get my custom icon to render and navigate to the correct component?
Leaving this as an answer hoping it helps someone else down the road. After sleeping on this I examined my Tab.Screen again and I remembered for a TouchableOpacity to work it needed an onPress even though I was thinking the parent would take care of the navigation but this wasn't the case.
While this answer is somewhat accurate, with removing the TouchableOpacity, it would make the icon work, code:
<Tab.Screen
name={routes.FOO}
component={TestScreen}
options={{
tabBarIcon: ({ focused }) => (
<View style={styles.actionButton}>
<Image source={plus} style={styles.imageIcon} />
</View>
),
}}
/>
but it defeats the purpose of a custom button and the opacity change. After looking closer at options I wondered what if I passed down the navigation to onPress and used navigate?
Well it worked and I was left with:
<Tab.Screen
name={routes.FOO}
component={TestScreen}
options={({ navigation }) => ({
tabBarIcon: () => (
<TouchableOpacity onPress={() => navigation.navigate(routes.FOO)}>
<View style={styles.actionButton}>
<Image source={plus} style={styles.imageIcon} />
</View>
</TouchableOpacity>
),
})}
/>
Your TouchableOpacity is overlap with react navigation internal press handler, just wrap your icon with View
If you want customize press behavior of tab icon pass the listener object to listener props https://reactnavigation.org/docs/navigation-events/#listeners-prop-on-screen

ReactNative WebView not rendering on web, but works fine on Android

Used versions:
"expo": "^36.0.2",
"react": "16.9.0",
"react-dom": "^16.8.6",
"react-native": "0.61.4",
"react-native-web": "0.11.7",
"react-native-webview": "^8.1.2"
Used React Native code:
<WebView
source={{uri: 'https://www.somedomain.com/'}}
style={{marginTop: 22, flex: 1}}
injectedJavaScript={this.state.contentScript}
domStorageEnabled={true}
startInLoadingState={true}
onMessage={this.receiveMessage}
ref={this.props.webview}
/>
Only a red border is present on the web version meanwhile on the Android it loads fine.
No errors present. Could this be a known issue? But I can't find it reported anywhere.
Currently WebView is not supported by expo-web. Check Platform Compatibility for more information.
But if you want to load your WebView inside expo-web, place it inside iframe as below,
import * as React from "react";
import { View, Platform } from "react-native";
import { WebView } from "react-native-webview";
export default class App extends React.Component {
render() {
return Platform.OS === "web" ? (
<iframe src="https://www.somedomain.com/" height={'100%'} width={'100%'} />
) : (
<View style={{ flex: 1 }}>
<WebView
source={{ uri: "https://www.somedomain.com/" }}
style={{marginTop: 22, flex: 1}}
/>
</View>
)
}
}
Hope this helps you. Feel free for doubts.

react native NativeBase CheckBox not working

I am using:
"native-base": "^2.12.1",
"react-native": "0.59.5",
I have used checkbox and made a custom checkboxGroup and it was working. now I want to create a customCheckBox but it doesn't do anything,it's not getting checked, I even can not change it's color.
I tried to use it the simplest way possible as document says but it's still not working with a blue color.
here is what it looks like https://pasteboard.co/Ila4cfR.png
const CustomChBx = ({label, onPress, disabled, checked, textStyle}) => {
const {_chbx, _label, _wrapper} = styles;
return (
<View style={_wrapper}>
<Text style={[_label, textStyle]}>{label}</Text>
<CheckBox>
style={_chbx}
checked={checked}
disabled={disabled}
onPress={onPress}
color={Colors.accentColor}
</CheckBox>
</View>
);
};
i copied and pasted this code and then edited it, it's working !!!
<ListItem>
CheckBox checked={true} />
<Body>
<Text>Daily Stand Up</Text>
</Body>
</ListItem>