react-native-webview : For iOS text too small
Asked Answered
C

3

27

I have used react-native-webview for rendering HTML text. But text is too small in iOS while in android it is perfect.

Here are lines of code :

import { WebView } from "react-native-webview";


render() {
  <WebView
        originWhitelist={['*']}
        source={{ html: '<p>This is a static HTML source!</p>' }}
  />
}

Attaching screenshot :

enter image description here

Cheekbone answered 5/3, 2019 at 7:20 Comment(3)
Related: #57753337Tailpipe
Funny, my iOS fonts are great and my Droid fonts are HUGE!Pentatomic
@OneInaMillionApps did you find a solution ?Obelize
C
76

Using the viewport meta tag to control layout on mobile browsers

<meta name="viewport" content="width=device-width, initial-scale=1">

<WebView
      originWhitelist={['*']}
      source={{ html: '<html><head><meta name="viewport" content="width=device-width, initial-scale=1.0"></head><body><p>This is a static HTML source!</p></body></html>' }}
/>

link :https://github.com/react-native-community/react-native-webview/issues/386

Cheekbone answered 5/3, 2019 at 7:54 Comment(2)
According my experiences HTML code should have valid DOCTYPE and html strcuture to render in web-view. If your content just "the body part", wrap it with html and body structure with DOCTYPE annotation to render correctly. Like <!DOCTYPE html><html><head><meta name="viewport" content="width=device-width, initial-scale=1.0"></head><body>${yourHtml}</body></html>Penology
thank you this works and helped :-) also wrapping content body content around headers in the WebView prevents its modification within body :-)Froh
V
2

Additionally to the <meta> you can add <style> tag into the <head> section to scale the font:

<style>
    body { font-size: 120%; word-wrap: break-word; overflow-wrap: break-word; }
</style>
Vladikavkaz answered 6/11, 2019 at 13:10 Comment(0)
B
1

This works pretty fine to me,

    <!DOCTYPE html>
    <html>
      <head>
        <meta name="viewport" content="width=device-width" initial-scale="1.00" maximum-scale="1.0">
      </head>
      <body>
        <p style='text-align:center;'>
           Hello World!
       </p>
      </body>
    </html>

Works in both Android and IOS

Bozcaada answered 13/4, 2023 at 6:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.