react-native icon indicating copy to clipboard operation
react-native copied to clipboard

'absolute' property not working react native while back to screen android.

Open reformer opened this issue 10 years ago • 31 comments

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.

reformer avatar Jul 20 '16 10:07 reformer

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 `

alzalabany avatar Oct 01 '16 19:10 alzalabany

+1

mishig25 avatar Nov 30 '16 02:11 mishig25

+1

gorjanz avatar Nov 30 '16 15:11 gorjanz

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.

reformer avatar Dec 04 '16 06:12 reformer

I have the same problem... @reformer where did you swap this code at?

SudoPlz avatar Dec 28 '16 14:12 SudoPlz

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 avatar Dec 28 '16 15:12 SudoPlz

@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 avatar Feb 03 '17 16:02 robbykim

@robbykim
Does it work if you

  1. remove the onLayout function
  2. set the width and height in a static way,
  3. 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..!

SudoPlz avatar Feb 03 '17 17:02 SudoPlz

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!

robbykim avatar Feb 03 '17 17:02 robbykim

Cool!! Good job man.

SudoPlz avatar Feb 03 '17 17:02 SudoPlz

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:

screen shot 2017-04-26 at 5 55 33 pm screen shot 2017-04-26 at 5 56 08 pm

Just tested today with latest version of react native.

kpink224 avatar Apr 25 '17 17:04 kpink224

I'm also having the same issue. @kpink224 @christopherdro

thevishnupradeep avatar Apr 28 '17 09:04 thevishnupradeep

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.

johuder33 avatar May 07 '17 21:05 johuder33

Another example showing how broken this is on Android: https://snack.expo.io/BkRSSXylZ

markdowney avatar May 09 '17 11:05 markdowney

this issue is braking my head!!! any fix about this? :(

cinder92 avatar Jun 02 '17 00:06 cinder92

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

preview

vbahtev avatar Jun 17 '17 12:06 vbahtev

@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 avatar Jun 18 '17 15:06 kpink224

@kpink224 yes understand you. But can you provide example source code ? Thanks

vbahtev avatar Jun 19 '17 15:06 vbahtev

@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!

kpink224 avatar Jun 19 '17 16:06 kpink224

mark

yuhanle avatar Jul 05 '17 12:07 yuhanle