Search code examples
androidcssreact-nativeflexboxreact-native-flexbox

Right is Left on React Native


Trying to display a List item within renderRow. I already implemented RTL in my project as defined on react native documentation, and I am getting a positive for console.log(I18nManager.isRTL ? 'yes' : 'no').
I am trying to present a designed table cell, so it's an image, on top of which I am trying to layout my items. So the logo is defined in styles like this:

var styles = StyleSheet.create({
  logo:{
    position: 'absolute',
    top:11,
    right:11,
    width: 26,
    height: 26
  }
  frame: {
    flex: 1,
    flexDirection:  'row',
    margin: 5,
  },


txtFirstName:{
    position:'absolute',
    top:7,
    right:40,
    marginRight:36,
    color:'white',
    fontSize:PixelRatio.get()*4/PixelRatio.getFontScale(),
    fontWeight:'bold',
    textAlign:'right',
    textShadowColor: 'black',
    textShadowOffset: {width:2,height:2},
    writingDirection : 'rtl'
  },

txtSecondName:{
    position:'absolute',
    top:17,
    right:40,
    marginRight:36,
    color:'white',
    fontSize:PixelRatio.get()*3/PixelRatio.getFontScale(),
    fontWeight:'bold',
    textAlign:'right',
    textShadowColor: 'black',
    textShadowOffset: {width:2,height:2},
    writingDirection : 'rtl'
  },

txtMainText:{
    position:'absolute',
    marginRight:36,
    color:'white',
    fontWeight:'bold',
    textAlign:'right',
    textShadowColor: 'black',
    textShadowOffset: {width:2,height:2},
    writingDirection : 'rtl',
    fontSize:PixelRatio.getPixelSizeForLayoutSize(3),
  },

});

  renderRow(rowData, sectionID, rowID) {
    return(
    <TouchableOpacity onPress={()=>this.showBusiness(rowData)}>
      <View style={{flex:1}}>
        <Image style={styles.logo} resizeMode = 'cover' source=}require('../images/logo.png’){/>
        <Image source={require('../images/mainFrame.png’){ style={styles.frame}/>
    <Text style={[styles.txtMainText,styles.txtFirstName]}>
      טקסט
    </Text>
    <Text style={[styles.txtMainText,styles.txtSecondName]}>
      מיושר לימין
    </Text>

      </View>
    </TouchableOpacity>
  );
  }

The result is disappointing.

Here's how it should look like: enter image description here

and here's how it is right now: enter image description here

What bothers me most is that it used to look okay, and I am not sure what blew it this way.

Also, the "Loading" text shows on the right of the window when the app starts.


Solution

  • As according to the documentation: "we map the left/right styles from the JS side to start/end, all left in code for RTL layout becomes "right" on screen, and right in code becomes "left" on screen."... Have you considered using left instead of right for your positioning? Alternatively, consider using flex-start or flex-end for the desired result.