bebnev / react-native-user-agent

Library that helps you to get mobile application user agent and web view user agent strings
MIT License
41 stars 38 forks source link

how to use this? i can't understand #22

Open haofeng123 opened 3 years ago

haofeng123 commented 3 years ago

import UserAgent from 'react-native-user-agent';

UserAgent.getUserAgent();

render() {
   var url = 'http://qun.hk/';
    return (
        <ScrollView
            automaticallyAdjustContentInsets={false}
            contentOffset={{top:20}}
            bounces={false}
            style={styles.container}>                             

            <StatusBar barStyle='light-content' backgroundColor='rgba(40,116,203,1)' translucent={true}></StatusBar>
            <WebView
                   nativeConfig={
                        {
                            props: {
                                backgroundColor: '#ffffff',
                                flex: 1,
                            }
                        }
                  }
                  ref={WEBVIEW_REF}
                  style={styles.webView}  
                  source={{uri:url,method: 'GET'}}  
                  javaScriptEnabled={true}  
                  domStorageEnabled={true}  
                  scalesPageToFit={false} 
                  mixedContentMode={'always'}
                  userAgent="Cordova-User-Agent"
                  // onMessage={(event) => {console.warn(event.nativeEvent.data);}}
                  onMessage={this.onMessage}
                  onNavigationStateChange={(e)=>this.onNavigationStateChange(e)}
                  />
        </ScrollView>
    );
}
pankajgupta1 commented 3 years ago

I used in this way

import UAParser from 'ua-parser-js' import UserAgent from 'react-native-user-agent'

const userAgent = UserAgent.getUserAgent() const parser = new UAParser(userAgent).getResult()

const {device, os, browser} = parser const {type, vendor, model} = device const {name, version} = os const {name, major} = browser

I used in this way. This is working good for me