V
V
Valentin Khoroshilov2019-11-23 19:14:54
JavaScript
Valentin Khoroshilov, 2019-11-23 19:14:54

How to make a local WebView in Expo?

How to display local html&css file in snack.expo?

import React, { Component } from 'react';
import { StyleSheet, View, Text, WebView } from 'react-native';

export default class Screen3 extends Component {
  //Screen3 Component
  render() {
    const htmlURL = require('./res/index.html').uri;

    return (
      <WebView
        originWhitelist={['*']}
        source={{htmlURL}}
        useWebKit={true}
        style={{ flex: 1 }}
        javaScriptEnabled={true}
      />
    );
  }
}

Instead of a website, a white screen is displayed
p.s. if you share materials on studying react native & expo, I will be very grateful

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Alexandrovich, 2019-11-24
@RomReed

I had the same task. helped for android put the file in android/app/src/main/asstes and specify
source={ uri: "file:///android_asset/YOUR FILE"}. and ios is simpler and works with half a kick (put the file next to it and use required to specify the path).

D
dim5on, 2020-01-13
@dim5on

Add to WebView width:100%

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question