Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

text input's placeholder doesnt support RTL when using password type in React native

Tags:

react-native

when I want to use password type in text input with secureTextEntry props, placeholder doesn't support RTL

<TextInput style={styles.input}
                                   value={this.state.password}
                                   secureTextEntry={true}
                                   placeholder="الزامی"
                                   underlineColorAndroid="transparent"
                                   onChangeText={(text) => this.setState({password: text})}/>

and result

enter image description here

What is the solution to this problem?

like image 272
Mohsen Haghighatkhah Avatar asked Sep 13 '25 08:09

Mohsen Haghighatkhah


1 Answers

Please check this code snippet, its working with RTL and LTR conditions. I have also attach code snippet snack.expo.io

import { I18nManager,Text,TextInput, View, StyleSheet } from 'react-native';

    <View style={{ borderWidth: 1, marginTop: 20, borderColor: '#000' }}>
          <TextInput
            style={{
              color: '#000',
              borderColor: '#000',
              textAlign: I18nManager.isRTL ? 'right' : 'left',
            }}
            value={this.state.password}
            placeholder="الزامی"
            placeholderTextColor="#303030"
            secureTextEntry={true}
            underlineColorAndroid="transparent"
            onChangeText={text => this.setState({ password: text })}
          />
        </View>

You need to add I18nManager to check your UI is in RTL mode or in LTR mode

like image 121
Vishal Dhanotiya Avatar answered Sep 16 '25 11:09

Vishal Dhanotiya