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,6 +318,11 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
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 326
   @ReactProp(name = "scalesPageToFit")
322 327
   public void setScalesPageToFit(WebView view, boolean enabled) {
323 328
     view.getSettings().setLoadWithOverviewMode(enabled);

+ 7
- 0
src/WebViewTypes.ts View File

@@ -237,6 +237,7 @@ export interface AndroidNativeWebViewProps extends CommonNativeWebViewProps {
237 237
   onContentSizeChange?: (event: WebViewEvent) => void;
238 238
   overScrollMode?: OverScrollModeType;
239 239
   saveFormDataDisabled?: boolean;
240
+  textZoom?: number;
240 241
   thirdPartyCookiesEnabled?: boolean;
241 242
   urlPrefixesForDefaultIntent?: ReadonlyArray<string>;
242 243
 }
@@ -480,6 +481,12 @@ export interface AndroidWebViewProps extends WebViewSharedProps {
480 481
    */
481 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 491
    * Specifies the mixed content mode. i.e WebView will allow a secure origin to load content from any other origin.
485 492
    *