Browse Source

feat(android): textZoom prop to limit scaling issues (#414)

When setting a custom font size in the Android system, an undesirable scale of the site interface in WebView occurs.

I researched that when setting the standard textZoom (100) parameter size, this undesirable effect disappears.

This can be very useful if you need to avoid the scale of content in WebView when changing the size of system fonts, or change textZoom property directly.

Example:

`
<WebView
  textZoom={100}
/>
`
mr.sadvit 5 years ago
parent
commit
82fe6e2c3d

+ 5
- 0
android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java View File

318
     }
318
     }
319
   }
319
   }
320
 
320
 
321
+  @ReactProp(name = "textZoom")
322
+  public void setTextZoom(WebView view, int value) {
323
+    view.getSettings().setTextZoom(value);
324
+  }
325
+
321
   @ReactProp(name = "scalesPageToFit")
326
   @ReactProp(name = "scalesPageToFit")
322
   public void setScalesPageToFit(WebView view, boolean enabled) {
327
   public void setScalesPageToFit(WebView view, boolean enabled) {
323
     view.getSettings().setLoadWithOverviewMode(enabled);
328
     view.getSettings().setLoadWithOverviewMode(enabled);

+ 7
- 0
src/WebViewTypes.ts View File

237
   onContentSizeChange?: (event: WebViewEvent) => void;
237
   onContentSizeChange?: (event: WebViewEvent) => void;
238
   overScrollMode?: OverScrollModeType;
238
   overScrollMode?: OverScrollModeType;
239
   saveFormDataDisabled?: boolean;
239
   saveFormDataDisabled?: boolean;
240
+  textZoom?: number;
240
   thirdPartyCookiesEnabled?: boolean;
241
   thirdPartyCookiesEnabled?: boolean;
241
   urlPrefixesForDefaultIntent?: ReadonlyArray<string>;
242
   urlPrefixesForDefaultIntent?: ReadonlyArray<string>;
242
 }
243
 }
480
    */
481
    */
481
   userAgent?: string;
482
   userAgent?: string;
482
 
483
 
484
+  /**
485
+   * Sets number that controls text zoom of the page in percent.
486
+   * @platform android
487
+   */
488
+  textZoom?: number;
489
+
483
   /**
490
   /**
484
    * Specifies the mixed content mode. i.e WebView will allow a secure origin to load content from any other origin.
491
    * Specifies the mixed content mode. i.e WebView will allow a secure origin to load content from any other origin.
485
    *
492
    *