@@ -20,6 +20,7 @@ import {
20
20
21
21
const DEFAULT_GOOGLE_API_URL =
22
22
'https://places.googleapis.com/v1/places:autocomplete' ;
23
+
23
24
const GooglePlacesTextInput = forwardRef (
24
25
(
25
26
{
@@ -37,6 +38,7 @@ const GooglePlacesTextInput = forwardRef(
37
38
debounceDelay = 200 ,
38
39
showLoadingIndicator = true ,
39
40
showClearButton = true ,
41
+ forceRTL = undefined ,
40
42
style = { } ,
41
43
} ,
42
44
ref
@@ -154,8 +156,11 @@ const GooglePlacesTextInput = forwardRef(
154
156
}
155
157
} ;
156
158
157
- // Update text alignment based on language
158
- const isRTL = I18nManager . isRTL ;
159
+ // RTL detection logic
160
+ const isRTL =
161
+ forceRTL !== undefined
162
+ ? forceRTL
163
+ : isRTLText ( placeHolderText ) || I18nManager . isRTL ;
159
164
160
165
const renderSuggestion = ( { item } ) => {
161
166
const { mainText, secondaryText } = item . placePrediction . structuredFormat ;
@@ -177,7 +182,7 @@ const GooglePlacesTextInput = forwardRef(
177
182
style = { [
178
183
styles . mainText ,
179
184
style . suggestionText ?. main ,
180
- isRTL && styles . rtlText ,
185
+ { textAlign : isRTL ? 'right' : 'left' } ,
181
186
] }
182
187
>
183
188
{ mainText . text }
@@ -187,7 +192,7 @@ const GooglePlacesTextInput = forwardRef(
187
192
style = { [
188
193
styles . secondaryText ,
189
194
style . suggestionText ?. secondary ,
190
- isRTL && styles . rtlText ,
195
+ { textAlign : isRTL ? 'right' : 'left' } ,
191
196
] }
192
197
>
193
198
{ secondaryText . text }
@@ -224,7 +229,13 @@ const GooglePlacesTextInput = forwardRef(
224
229
style = { [
225
230
styles . input ,
226
231
style . input ,
227
- { paddingRight : showClearButton ? 75 : 45 } , // Adjust padding based on clear button visibility
232
+ {
233
+ // Icons are on the left when RTL, so add more padding on left
234
+ paddingLeft : isRTL ? ( showClearButton ? 75 : 45 ) : 15 ,
235
+ // Icons are on the right when LTR, so add more padding on right
236
+ paddingRight : isRTL ? 15 : showClearButton ? 75 : 45 ,
237
+ textAlign : isRTL ? 'right' : 'left' ,
238
+ } ,
228
239
] }
229
240
placeholder = { placeHolderText }
230
241
placeholderTextColor = { style . placeholder ?. color || '#666666' }
@@ -386,4 +397,14 @@ const styles = StyleSheet.create({
386
397
} ,
387
398
} ) ;
388
399
400
+ const isRTLText = ( text ) => {
401
+ if ( ! text ) return false ;
402
+ // Hebrew: \u0590-\u05FF
403
+ // Arabic: \u0600-\u06FF, \u0750-\u077F (Arabic Supplement), \u0870-\u089F (Arabic Extended-B)
404
+ // Arabic Presentation Forms: \uFB50-\uFDFF, \uFE70-\uFEFF
405
+ const rtlRegex =
406
+ / [ \u0590 - \u05FF \u0600 - \u06FF \u0750 - \u077F \u0870 - \u089F \uFB50 - \uFDFF \uFE70 - \uFEFF ] / ;
407
+ return rtlRegex . test ( text ) ;
408
+ } ;
409
+
389
410
export default GooglePlacesTextInput ;
0 commit comments