@@ -20,6 +20,7 @@ import {
2020
2121const DEFAULT_GOOGLE_API_URL =
2222 'https://places.googleapis.com/v1/places:autocomplete' ;
23+
2324const GooglePlacesTextInput = forwardRef (
2425 (
2526 {
@@ -37,6 +38,7 @@ const GooglePlacesTextInput = forwardRef(
3738 debounceDelay = 200 ,
3839 showLoadingIndicator = true ,
3940 showClearButton = true ,
41+ forceRTL = undefined ,
4042 style = { } ,
4143 } ,
4244 ref
@@ -154,8 +156,11 @@ const GooglePlacesTextInput = forwardRef(
154156 }
155157 } ;
156158
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 ;
159164
160165 const renderSuggestion = ( { item } ) => {
161166 const { mainText, secondaryText } = item . placePrediction . structuredFormat ;
@@ -177,7 +182,7 @@ const GooglePlacesTextInput = forwardRef(
177182 style = { [
178183 styles . mainText ,
179184 style . suggestionText ?. main ,
180- isRTL && styles . rtlText ,
185+ { textAlign : isRTL ? 'right' : 'left' } ,
181186 ] }
182187 >
183188 { mainText . text }
@@ -187,7 +192,7 @@ const GooglePlacesTextInput = forwardRef(
187192 style = { [
188193 styles . secondaryText ,
189194 style . suggestionText ?. secondary ,
190- isRTL && styles . rtlText ,
195+ { textAlign : isRTL ? 'right' : 'left' } ,
191196 ] }
192197 >
193198 { secondaryText . text }
@@ -224,7 +229,13 @@ const GooglePlacesTextInput = forwardRef(
224229 style = { [
225230 styles . input ,
226231 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+ } ,
228239 ] }
229240 placeholder = { placeHolderText }
230241 placeholderTextColor = { style . placeholder ?. color || '#666666' }
@@ -386,4 +397,14 @@ const styles = StyleSheet.create({
386397 } ,
387398} ) ;
388399
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+
389410export default GooglePlacesTextInput ;
0 commit comments