Code Monkey home page Code Monkey logo

react-native-geckoview's Introduction

react-native-geckoview

A fully functional implementation of GeckoView on android for react native. The component supports two-way messaging similar to react-native-webview.

Installation

yarn add @ammarahmed/react-native-geckoview

Basic Example

import GeckoView from "react-native-geckoview";
const App = () => {
  const ref = useRef<GeckoView>(null);

  return (
    <SafeAreaView
      style={{
        backgroundColor: "white",
        flex: 1,
      }}
    >
      <GeckoView
        ref={ref}
        style={{
          flex: 1,
        }}
        source={{ uri: "https://google.com" }}
        onLoadingStart={(e) => {
          console.log(e.nativeEvent.uri);
        }}
        onLoadingFinish={(e) => {
          console.log("success:", e.nativeEvent.success);
        }}
        remoteDebugging={true}
        onMessage={(event) => {
          console.log(event.nativeEvent);
        }}
        injectedJavaScript={
          'window.ReactNativeWebView.postMessage("hello world")'
        }
      />
    </SafeAreaView>
  );
};

API

GeckoView implements a simple interface with basic url loading & messaging features.

interface GeckoViewInterface extends ViewProps {
  source?: { html?: string; uri?: string };
  forceDarkOn?: boolean;
  autoFillEnabled?: boolean;
  remoteDebugging?: boolean;
  userAgent?: string;
  onLoadingStart?: (event: NativeSyntheticEvent<{ uri: string }>) => void;
  onLoadingFinish?: (event: NativeSyntheticEvent<{ success: string }>) => void;
  onLoadingError?: (
    event: NativeSyntheticEvent<{ error: string; uri: string }>
  ) => void;
  onMessage?: (event: NativeSyntheticEvent<any>) => void;
  onLoadingProgress?: (
    event: NativeSyntheticEvent<{ progress: number }>
  ) => void;
  onMessagingDisconnected?: () => void;
  injectedJavaScript?: string;
}

Commands

A small set of commands can also be invoked on ref of GeckoView for basic messaging & page navigation.

type WebViewCommands = {
  goBack: () => void;
  goForward: () => void;
  reload: () => void;
  stopLoading: () => void;
  postMessage: (message: string) => void;
  injectJavaScript: (script: string) => void;
  loadUrl: (url: string) => void;
  requestFocus: () => void;
  clearHistory: () => void;
  clearCache: () => void;
  connectMessagingPort: () => void;
};

Commands can be invoked on the GeckoView ref.

const ref = useRef<GeckoView>(null);

// In your function
ref.current?.reload();

Messaging

Messaging works through an extension for GeckoView which can be found at the root of the project. Copy contents of extensions/messaging to your Apps's android/app/src/main/assets/messaging folder.

Thanks to

MIT License

react-native-geckoview's People

Contributors

ammarahm-ed avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-native-geckoview's Issues

User preferences or config settings

I am trying to disable the background network calls which geckoview Mozilla makes in the background but having issues while setting up the preferences,

I found this article https://winaero.com/disable-firefox-captive-portal-and-connection-to-detectportal-firefox-com/#To_Disable_Firefox_Captive_Portal_and_Connection_to_detectportalfirefoxcom where you can set user preference setup like how you modify about:config for Mozilla browser, but I couldn't find the right implementation of it in geckoview documentation

user_pref("network.captive-portal-service.enabled", false);

Too Many Bugs!! Can't Be Use, Can't Help To Fix

  1. You need to add this in build.gradle before you can use this repo/component
maven {
               url "https://maven.mozilla.org/maven2/"
           }
  1. import have to be use this import GeckoView from '@ammarahmed/react-native-geckoview'
  2. Force close in android if you scroll the webview to the end. the bugs very similar with [Crash] WebView inside ScrollView crash on scroll end - Android in scrollview see this as references react-native-webview/react-native-webview#2364 even i'm not using scrollview or i have put overScrollMode="never"
  3. Sometimes it goes blank black and u can't put state like setLoading(true) in onLoadingStart
  4. Postmessage not working from Website with jquery. It's working fine in react-native-webview but when i change to geckoView it doesn't working anymore

Sorry can't help to fix since i'm noob with java & react

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.