1

i want to show the web page in a modal, I am using this line of code but it is showing me blank modal.

<WebView source={{uri: 'https://github.com/facebook/react-native'}}/>
Bilal Yaqoob
  • 790
  • 1
  • 10
  • 22

2 Answers2

4

You should have provided more from code then it could help to fix the bug on your code self. However format of the code should be right below.

import React from 'react';
import { View, Button, Modal, StyleSheet, ActivityIndicator } from 'react-native';
import { WebView } from 'react-native-webview';

class TestClass extends React.Component {
    constructor(props) {
        super(props)
        this.state = {
            showModal : false
        }
    }



    ActivityIndicatorLoadingView() {
       return (
         <ActivityIndicator
            color="#009688"
            size="large"
            style={styles.ActivityIndicatorStyle}
         /> 
       );
    }

    render(){
        return(
            <View style={{flex : 1, justifyContent : 'center', alignItems: 'center'}}>
                <Button title="Press" onPress={() => this.setState({showModal : !this.state.showModal})}/>
                <Modal  visible={this.state.showModal}>
                    <View style={styles.modal}>
                        <View style={styles.modalContainer}>
                            <WebView 
                                style={{ flex : 1 }} 
                                source={{uri: 'https://github.com/facebook/react-native'}}/>
                                renderLoading={this.ActivityIndicatorLoadingView}
                        </View>
                    </View>
                </Modal>
            </View>
        )
    }
}
const styles = StyleSheet.create({
    modal : {
        flex : 1,
        justifyContent : 'center',
        alignItems : 'center',
        backgroundColor: 'rgba(0,0,0,0.5)'
    },
    modalContainer : {
        backgroundColor : 'white',
        width : '90%',
        height : '90%',
    },
    ActivityIndicatorStyle: {
        flex: 1,
        justifyContent: 'center',
    },
})
export default TestClass
Chanuka Sandeepa
  • 680
  • 6
  • 10
3

I developed nice package for this. If you want you can examine or use it. The link of the package is https://github.com/ilkerkesici/react-native-beauty-webview.

İlker
  • 476
  • 3
  • 5