'absolute' property not working react native while back to screen android.
I'm working on react native video conferencing module. I showing complete view of remote video full screen and self video in small screen just bottom right, styles is,
remoteView: {
flex:1,
justifyContent: 'center',
alignItems: 'center',
alignSelf:'center',
width: width,
height: height,
},
selfView: {
width:width*.2,
height:height*.2,
right: 5,
bottom: 5,
position: 'absolute',
},
My Code,
return (
<View style={styles.mainContainer}>
{
mapHash(this.state.remoteList, function(remote, index)
return (<RTCView key={remoteIndex} streamURL={remoteStreamURL} style={styles.remoteView} />);
})
}
<RTCView streamURL={this.state.selfViewSrc} style={styles.selfView}/>
<TouchableHighlight
style={styles.otherScreen}
onPress={this._openOtherScreen}>
{
(Platform.OS === 'android')
?
<Image style={styles.iconnav} source= require('./img/imageP.png')}/>
:
<Image style={styles.iconnav} source= require('image!imageP')}/>
}
</TouchableHighlight>
<TouchableHighlight
style={styles.quit}
onPress={ () => this.closeEvent()
}>
{
(Platform.OS === 'android') ?
<Image
style={styles.iconnav}
source={require('./img/exit.png')}/>
:
<Image
style={styles.iconnav}
source={require('image!exit')} />
}
</TouchableHighlight>
</View>
);
My mainContainer style is,
mainContainer: {
flex:1,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
alignSelf : 'stretch',
right: 0,
bottom: 0,
top:0,
left:0,
position: 'absolute',
backgroundColor:'#424242',
},
Now the scenario is when i open other screen and come back video view screen then my remote view showing me properly but my self video view not showing. But icons showing proper position (Note : i run same code in iOS device it working properly not in android). I run one test case i make small frame of remote video and again run my application that time when i comeback other screen my self video showing on its position. That means in full remote video it also showing but self video view going back to remote video. How to bring to front my self video.
same here, android position absolute not showing correctely
` users.map(u=>( <TouchableHighlight key={u.id} style={{zIndex:2,borderRightColor:'#ccc',borderRightWidth:3}} onPress={()=>{}}> <Animate.Image transition={["width","height"]} source={p} defaultSource={Logo} style={{ width: u.id===id?80:40, height: u.id===id?80:40, borderRadius: u.id===id?40:20, top: i < 3 ? 0 : u.id===id ?0 : 50, position:'absolute', right:u.id===id?null:(i<3?i:i-3)*50, left:u.id===id?10:null, }} />);
this renders as expected in ios but not in android `
+1
+1
I resolved this issue. just swapping my code line.. the correct code lines are,
<RTCView streamURL={this.state.selfViewSrc} style={styles.selfView}/>
{
mapHash(this.state.remoteList, function(remote, index)
return (
<RTCView key={remoteIndex} streamURL={remoteStreamURL} style={styles.remoteView} />);
})
}
RTC self View line write first then RTC remote view.
I have the same problem... @reformer where did you swap this code at?
Never mind, I found that most of the times, the view that is styled with position: 'absolute' must always have a defined width and height, otherwise it disappears in Android. I solved the problem, by simply defining a width and a height on the absolute view.
@SudoPlz I tried putting a width and height on my absolute view and its still showing a white space where the component is supposed to render. It renders properly on iOS but doesn't on Android. I'm not really sure what I'm doing wrong :\
my current render function and the mainContainer styles are below. I've tried adding a height: 100 to the styles and it renders the height but the component is still hidden somewhere with a white box in its place. Any ideas?
<View
onLayout={event => setTabHeight(event.nativeEvent.layout.height)}
style={styles.mainContainer}
>
<View style={demographicStyle}>
{demographicDetails}
</View>
<ResultsPatientCompareContainer
results={results[calculatorType]}
comparedResults={comparedResults}
/>
</View>
mainContainer: {
width: Dimensions.get('window').width,
position: 'absolute',
shadowColor: '#000',
shadowOpacity: 0.2,
shadowOffset: { height: 1 },
},
@robbykim
Does it work if you
- remove the
onLayoutfunction - set the width and height in a static way,
- Add a top: 0 value ?
mainContainer: {
width: 100,
height: 100,
position: 'absolute',
shadowColor: '#000',
shadowOpacity: 0.2,
shadowOffset: { height: 1 },
},
Try that, it might give you a hint on what to do next..!
so i need the onLayout because that components height is more dynamic and changes based on information it receives. however, i kinda fixed the problem by putting a height on the parent element. react native is absolute relative to its parent, the parent didn't have a height and it didn't know what to do haha. i think i got it now!
Cool!! Good job man.
Is this still an issue for anyone else? I've figured out how to work around it but would love for this to work consistently on all devices.
As of now, in order to even get something to show up on android, the child has to either have specified height and width or inherit them from its parent. Also, the element has to fit entirely within it's parent to be fully displayed - which may be more annoying.
Here are images of this issue:

Just tested today with latest version of react native.
I'm also having the same issue. @kpink224 @christopherdro
I have had similar issue with that, I realized that remove elevation prop fixex the issue, maybe you can try adding elevation property in android instead zIndex.
Another example showing how broken this is on Android: https://snack.expo.io/BkRSSXylZ
this issue is braking my head!!! any fix about this? :(
You need to add another root container: If you want red box to not be cut from @kpink224 's comment you need to add another container that have only one style property style={{flex: 1}}
full code ( work for android and iOS )
<View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
<Text> Some content here</Text>
<View style={{flex: 1}}>
<View style={{width: 150, height: 150, backgroundColor: '#C6C6C6'}}>
</View>
<View style={{position: 'absolute', top: 0, right: -50, width: 70, height: 70, backgroundColor: '#FF0000'}}>
</View>
</View>
<Text> Some content here</Text>
</View>
result
@vbahtev While you are right in your implementation and it works for this specific situation, the problem still persists when the view is not within the parents boundaries (something that iOS handles). The wrapping view here provides that parent boundary that stretches to the sides of the screen so that the red box can be seen.
@kpink224 yes understand you. But can you provide example source code ? Thanks
@vbahtev I feel the code above and what @markdowney provided shows the problem pretty accurately. I guess for how I'm using it, I want to show a progress bar (not the one provided in react-native. I wanted a custom one) that has a arrow that points up at the progress. When progress is 0% or 100%, the arrow must go outside the boundaries of the bar component. I can fix it by adding a margin but prefer not to solve it that way due to UX constraints. It works obviously with iOS but is cut off in android. Thanks for helping out with this!
mark