How to use BottomSheet inside model - react-native

I want to add bottom sheet in Modal. I am using reanimated-bottom-sheet and react native modal.
But when I use BottomSheet inside Modal gesture not work and can't closeBottomSheet with swiping down.
I searched and I found this is RCGH problem.
So I decide to use View instead of Modal.
but View doesn't cover Header.
This is bottomSheet code:
<View style={BottomSheetStyles.container}>
<TouchableWithoutFeedback onPress={handleOutsidePress}>
<Animated.View style={[BottomSheetStyles.dropShadow, { opacity }]} />
</TouchableWithoutFeedback>
<Animated.Code exec={onChange(position, [cond(eq(position, 1), call([], onClose))])} />
<BottomSheet
ref={sheet}
initialSnap={zeroIndex}
snapPoints={snapPoints}
callbackNode={position}
renderHeader={() => <View style={BottomSheetStyles.header} />}
renderContent={() => (
<View style={[BottomSheetStyles.content, { height: "100%" }]}>{children}</View>
)}
/>
</View>
and this is styles:
const BottomSheetStyles = StyleSheet.create({
container: {
position: "absolute",
top: 0,
left: 0,
right: 0,
bottom: 0,
flex: 1,
zIndex: 100,
},
dropShadow: {
position: "absolute",
top: 0,
left: 0,
right: 0,
bottom: 0,
flex: 1,
zIndex: 100,
backgroundColor: "rgba(0, 0, 0, 0.3)",
},
header: {
backgroundColor: Colors.greyC4C,
width: 90,
height: 7,
margin: 5,
alignSelf: "center",
borderRadius: 11,
},
content: {
backgroundColor: Colors.whiteFFF,
paddingTop: 18,
borderTopLeftRadius: 22,
borderTopRightRadius: 22,
},
});
So problem can be solve either whit solving gesture in Modal or do something to cover Header with View.
I am using React Navigation.

Related

Touchable Opacity messes up width in row container

I'm trying to make these two Card components appear next to each other in a row as shown
here which seems to work when I wrap the component in a View, but appears like this with a bunch of unnecessary space in between when I try it with a TouchableOpacity.
Here is my code for the Card component (currently with TouchableOpacity on and the View wrapper commented out):
export const NavCard = ({
title,
height = 200,
onPress = null,
background = null,
}) => {
return (
<TouchableOpacity
onPress={onPress}
style={[
{ height: height },
background ? styles.cardImage : styles.noImage,
]}
>
{/* <View
style={[
{ height: height },
background ? styles.cardImage : styles.noImage,
]}
> */}
<Image
source={background}
resizeMode="cover"
style={{
height: height,
width: "100%",
borderRadius: 15,
position: "absolute",
top: 0,
right: 0,
}}
/>
<View style={{ padding: 15 }}>
<Text style={styles.title}>{title}</Text>
<Image
style={styles.arrow}
source={require("../assets/arrow-right.png")}
/>
</View>
{/* </View> */}
</TouchableOpacity>
);
};
const styles = StyleSheet.create({
cardImage: {
flexGrow: 1,
margin: "2%",
borderRadius: 15,
},
noImage: {
flexGrow: 1,
margin: "2%",
borderRadius: 15,
backgroundColor: "#333436",
},
title: {
fontSize: 24,
color: "#E4E5EA",
fontWeight: "bold",
shadowColor: "#000000",
shadowOffset: { width: 2, height: 2 },
shadowOpacity: 1,
shadowRadius: 4,
},
arrow: {
width: 15,
height: 15,
resizeMode: "contain",
position: "absolute",
top: 22,
right: 20,
},
});
Here is the code for the screen:
const HomeScreen = ({ navigation }) => {
return (
<View style={styles.container}>
<View style={styles.rowContainer}>
<NavCard
title="Map"
height={180}
onPress={() => navigation.navigate("Map")}
background={require("../assets/pvdx1.png")}
></NavCard>
<NavCard
title="CAD"
height={180}
background={require("../assets/pvdx1.png")}
onPress={() => navigation.navigate("CADScreen")}
></NavCard>
</View>
</View>
);
};
const styles = StyleSheet.create({
container: {
paddingTop: 10,
padding: 4,
flex: 1,
},
rowContainer: {
flexDirection: "row",
justifyContent: "space-between",
},
body: {
paddingTop: 10,
fontSize: 16,
color: "#E4E5EA",
},
});
export default HomeScreen
Does anyone know why it's messing up the width of both components if the styles of the View and TouchableOpacity are exactly the same? I'm using React Native.
Edit: Have updated to use Image instead of ImageBackground (code now reflects this), but the result is the same.
I figured out the issue: I was importing TouchableOpacity from react-native-gesture-handler instead of react-native. Changed it and it works just fine.
Probably the problem is in your <ImageBackground /> , Because I replaced that with native <Image /> and it's working. here is how my Image looks, you can compare with your code:
<Image
style={{
height: height,
borderRadius: 15,
position: "absolute",
top: 0,
right: 0,
width: "100%"
}}
resizeMode="cover"
source={{ uri: "https://via.placeholder.com/250x150" }}
/>
Here you can check the working code
for me i had to also set the width on the TouchableOpacity (and the view within)
<TouchableOpacity
style={{flex: 1, width: '100%'}}

react native, how to make a limited view by another view?

I have this problem and I have not been able to solve it, how can I make view 1 limited by view 2?
I need view 1 not to leave the edges of view 2, the image is on the outside, it should be cropped limited by view 2, I don't know if I make myself understood
<View style={styles.container}>
<View style={styles.progressBar}>
<Animated.View style={[styles.absoluteFill, { borderRadius: 30, backgroundColor: colors.blue2, width }]} />
</View>
<Text style={styles.progressText}>
{`${progress}%`}
</Text>
</View>
const styles = StyleSheet.create({
absoluteFill: {
position: 'absolute',
left: 0,
right: 0,
top: 0,
bottom: 0,
},
progressText: {
position: 'absolute',
color: colors.white,
fontFamily: "OpenSans-Regular"
},
container: {
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
height: 30,
borderRadius: 30,
},
progressBar: {
//alignSelf: 'baseline',
height: 30,
width: '100%',
backgroundColor: colors.blue3,
borderRadius: 30
}
})
thank you
You need to add an overflow: hidden at your progressBar style.
progressBar: {
height: 30,
width: '100%',
overflow: 'hidden',
backgroundColor: colors.blue3,
borderRadius: 30
}
I did this live demo for you:
https://codesandbox.io/s/vibrant-fermi-49ztl?file=/src/App.js

Blur the Half of the image in react-native

i am using this module for displaying blur image. My question is blur is applied to bottom of the image. This issue is faced in Android but iOS working fine.
Please follow this issue in GitHub:- enter link description here
Here is the screenshots:-
Android:-
iOS:-
<View style={styles.container}>
<Text>Hi, I am some unblurred text</Text>
<Image source={{ uri: 'https://picsum.photos/200/300' }} style={styles.img} />
<BlurView style={styles.blur} blurType="light" blurAmount={10} />
</View>
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'flex-end',
alignItems: 'center',
position: 'relative',
zIndex: 1
},
img: {
flex: 1,
position: 'relative',
height: '100%',
zIndex: 2,
width: '100%'
},
blur: {
position: 'absolute',
left: 0,
bottom: 0,
right: 0,
height: '30%',
zIndex: 3
}
});
Hi, Just a case of styling each of the elements, in this case, its 30% high, but you can alter that figure on your project to be 50% or whatever you need it to be.
Hope this helps.

react-native trasparent overlay exposing some component

how can I create a transparent overlay exposing some component like buttons, icons? So that it can be used as a tutorial screen.
I want to achieve something like shown in the image.
You need a modal overlay. To achieve this, you must add a <View> with an opacity style over your current component. In that <View>, you must add your own custom images (with the arrows for example) and position them as you want.
To add an opacity, you can add a style with the opacity property, like this:
overlay: {
opacity: 0.5,
}
You can set the value of the opacity as you like (between 0 and 1).
If you want it to be as big as the screen and to be positioned over your component, you can add something like this:
overlay: {
position: 'absolute',
height: '100%',
width: '100%',
backgroundColor: '#fff',
opacity: 0.5,
}
or:
overlay: {
position: 'absolute',
top: 0,
right: 0,
bottom: 0,
left: 0,
backgroundColor: '#fff',
opacity: 0.5,
}
Now, for the holes in the overlay, that can be achieved by properly using the z-index property. As long as a component has a higher value of z-index, it will be on top of a component that has a lower value.
To assign the z-index to a style, use it like this:
onTop: {
zIndex: 2
}
below: {
zIndex: 1
}
Complete example
This is a working example of a modal overlay, where the text This is always on top, is always on top:
import React, { Component } from 'react';
import { Image, StyleSheet, View, Text } from 'react-native';
export default class App extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.mainText}>This is always on top</Text>
<View style={styles.overlay}>
<Text>This is an overlay</Text>
<Text>This is an overlay</Text>
<Text>This is an overlay</Text>
<Text>This is an overlay</Text>
<Text>This is an overlay</Text>
<Text>This is an overlay</Text>
<Text>This is an overlay</Text>
<Text>This is an overlay</Text>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex:1,
backgroundColor: "#00ff00",
top: 0,
right: 0,
bottom: 0,
left: 0,
justifyContent: "center",
alignItems: "center",
zIndex: 1
},
mainText:{
fontSize: 30,
zIndex: 3,
backgroundColor: '#ff0000',
},
overlay: {
position: 'absolute',
top: 0,
right: 0,
bottom: 0,
left: 0,
backgroundColor: '#fff',
color: '#000',
opacity: 0.5,
justifyContent: "center",
alignItems: "center",
fontSize: 24,
zIndex: 2
}
});
Apply these ideas to your working app, and you can achieve what you are looking for.

Style shoutem camera component

He, I was trying to put the right styles in place in order to see the focus image over the camera screen with a little padding on all sides, but somehow I could not get it done.
The shoutem.camera source looks like:
<View style={style.cameraContainer}>
<Camera
onBarCodeRead={this.onQRCodeScanned}
style={style.cameraView}
aspect={Camera.constants.Aspect.fill}
captureQuality={cameraQuality}
/>
<Image
source={require('../assets/images/focus-frame.png')}
style={style.cameraFocusFrame}
/>
</View>
I am asking for style.cameraContainer & style.cameraView & style.cameraFocusFrame.
The style rules for those styles can be found at the very end of themeName.js. Here it is from the default theme, Rubicon:
'shoutem.camera.QRCodeScanner': {
cameraContainer: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
cameraFocusFrame: {
width: 175,
height: 165,
resizeMode: 'contain',
},
cameraView: {
position: 'absolute',
left: 0,
right: 0,
top: 0,
bottom: 0,
},
noPermissionsMessage: {
alignSelf: 'center',
fontSize: 18,
lineHeight: 20,
},
}
We do intend to reimplement the focus frame to be responsive by nature, as you had mentioned.