I want to fix my Image. I use position: 'absolute', in iOS it works fine, but in android the image disappear. This is my code:
<Image style={{width: width, zIndex: 0, position: 'absolute', top: 0}}
source={require('../assets/2piano.png')}
resizeMode="contain"
/>
Please HELP!!!
This will work on both Android and iOS. Since your image is from the local resources you should give it a width:null and height:null in order to apply your own dimensions on it.
<View style={{width: 500, height:500}}>
<Image style={{width: null, height:null, zIndex: 0, position: 'absolute', top: 0, bottom:0, left:0, right:0}}
source={require('../assets/2piano.png')}
resizeMode="contain"
/>
</View>
For style:
twoPianoStyle: {
position: 'absolute',
height: '100%',
width: '100%'
}
Related
I am working on react native the below is one of the code snippet which I currently working on. My issue is with Pinch Gesture Handler.
<TapGestureHandler
numberOfTaps={2}
maxDelayMs={250}
ref={doubleTapRef}
onActivated={handleDoubleTap}
minPointers={5}
>
<Animated.View>
<PinchGestureHandler
onGestureEvent={onPinchEvent}
onHandlerStateChange={onPinchStateChange}
>
<Animated.Image
source={{ uri: imageUrl }}
style={{
width: windowWidth,
height: calculatedHeight,
borderColor: AppColors.palette.black,
transform: [{ scale: scale }]
}}
resizeMode='contain'
/>
</PinchGestureHandler>
<Animated.View style={[{
opacity,
borderRadius:100/2,
position: 'absolute',
alignItems: 'center',
justifyContent: 'center',
left: 0,
right: 0,
top: 0,
bottom: 0,
}]}>
<Image style={{resizeMode:"center"}} source=
{require('../../res/assets/images/heart.png')} fadeDuration={0}/>
</Animated.View>
</Animated.View>
</TapGestureHandler>
I have added TapGestureHandler and PinchGestureHandler, my problem is PinchGestureHandler for image zooming is not working properly some times it work sometimes not can any one suggest how to solve this issue.
I have a problem with positioning my image inside a container and that is when I give image position: absolute and top property image got cropped from the top here's the issue:
here's my code:
<View style={styles.OurTherapistsContainer}>
<View style={styles.therapistCard}>
<View style={styles.imageContainer}>
<Image style={styles.image} source={require('../assets/img/leong.png')} />
</View>
</View>
</View>
...
therapistCard: {
width: 150,
height: 150,
borderRadius: 25,
borderWidth: 1,
borderColor: '#DFEEFF',
overflow: 'hidden',
},
imageContainer: {
width: 150,
height: 150,
backgroundColor: 'red',
},
image: {
width: '100%',
height: '100%',
position: "absolute",
top: 30
}
how can I fix this?
Try using resizeMode in image style like
resizeMode:'contain'
set resizeMode to cover
<Image style={styles.image} resizeMode="cover" source {require('../assets/img/leong.png')} />
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.
So I'm setting a background image in react native but I need the position of the background image to be set to bottom. So if anyone knows how to achieve this.
I have tried adding backgroundPosition but it seems it is not supported
<ImageBackground
source={require("../assets/img/bg-top.png")}
// resizeMethod={'auto'}
style={{
width: "100%",
height: 120,
padding: 20,
paddingVertical: 40,
backgroundPosition: "bottom" // not working
}}
imageStyle={{
resizeMode: "cover",
alignSelf: "flex-end"
}}
>
<Text style={{ color: "#D8D8D8", fontSize: 16 }}>Login</Text>
</ImageBackground>;
I expect the image alignment should start from the bottom rather it starts from the top
React native provided bottom and position tag to set UI at bottom. Please replace backgroundPosition tag from image style into
position: 'absolute',
bottom:0
<ImageBackground
// resizeMethod={'auto'}
style={{
width: "100%",
height: 120,
backgroundColor:'#000',
padding: 20,
paddingVertical: 40,
position: 'absolute',
bottom:0
}}
imageStyle={{
resizeMode: "cover",
alignSelf: "flex-end"
}}
>
<Text style={{ color: "#D8D8D8", fontSize: 16 }}>Login</Text>
</ImageBackground>
Please check snack expo
https://snack.expo.io/#vishal7008/bottom-ui
The image inside ImageBackground has the default style:
position: 'absolute'
top: 0
bottom: 0
right: 0
left: 0
So, we can just remove the top: 0 by setting
top: undefined
together we have
<ImageBackground
source={require("../assets/img/bg-top.png")}
// resizeMethod={'auto'}
style={{
width: "100%",
height: 120,
padding: 20,
paddingVertical: 40,
overflow: 'hidden' // prevent image overflow the container
}}
imageStyle={{
resizeMode: "cover",
height: 200, // the image height
top: undefined
}}
>
<Text style={{ color: "#D8D8D8", fontSize: 16 }}>Login</Text>
</ImageBackground>
For implementing the position of the background image I use the following code, actually I use the ImageBackground component as the wrapper of the entire screen:
<ImageBackground
style={styles.screenWrapper}
imageStyle={styles.backgroundStyle}
source={{ uri: movieDetail?.image?.medium?.url }}
>
// children
~~~
const styles = createStyle({
screenWrapper: {
flex: 1,
position: 'relative',
},
backgroundStyle: {
resizeMode: 'cover',
position: 'absolute',
top: 0,
bottom: '45%',
},
Finally, I reach my desire:
Note: The above codes are not workable, it is just pseudo-code to convey my exact idea.
the backgroundPosition you know from CSS is not supported according the docs.
There is a similar question:
https://stackoverflow.com/a/53726116/9899193
Does this help you?
This code work different on iOS and Android - And I don`t understand why?
I try to make autocomplete, and list of suggestion render inside header component - but should be over header+Content
<View style={{flex: 1}}>
<View style={{
height: 50,
backgroundColor: 'red',
left: 0,
position: 'absolute',
right: 0,
top: 0,
zIndex: 1
}}>
<Text>Header</Text>
<View style={{
backgroundColor: '#3F9',
left: 50,
position: 'absolute',
height: 100,
right: 50,
top: 25,
zIndex: 1
}}><Text>Should overlay Content</Text></View>
</View>
<View style={{flex: 1, backgroundColor: 'yellow'}} >
<Text>Content</Text>
</View>
It's better to stay away from "zIndex" since it won't work as expected in Android. instead use the order of the elements along with position:'absolute' . it'll work fine.
reference - How to overlap in react-native
I think I found what happens.
As I read on Facebook documentation
The overflow style property defaults to hidden and cannot be changed on Android