Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# React Native WebView

![star this repo](https://img.shields.io/github/stars/react-native-webview/react-native-webview?style=flat-square)
![star this repo](https://img.shields.io/github/stars/react-native-gigya2-webview/react-native-gigya2-webview?style=flat-square)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
[![NPM Version](https://img.shields.io/npm/v/react-native-webview.svg?style=flat-square)](https://www.npmjs.com/package/react-native-webview)
![Npm Downloads](https://img.shields.io/npm/dm/react-native-webview.svg)
[![NPM Version](https://img.shields.io/npm/v/react-native-gigya2-webview.svg?style=flat-square)](https://www.npmjs.com/package/react-native-gigya2-webview)
![Npm Downloads](https://img.shields.io/npm/dm/react-native-gigya2-webview.svg)

**React Native WebView** is a community-maintained WebView component for React Native. It is intended to be a replacement for the built-in WebView (which was [removed from core](https://github.com/react-native-community/discussions-and-proposals/pull/3)).

Expand Down Expand Up @@ -45,12 +45,12 @@ This project follows [semantic versioning](https://semver.org/). We do not hesit

### Usage

Import the `WebView` component from `react-native-webview` and use it like so:
Import the `WebView` component from `react-native-gigya2-webview` and use it like so:

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

// ...
const MyWebComponent = () => {
Expand All @@ -63,11 +63,11 @@ For more, read the [API Reference](./docs/Reference.md) and [Guide](./docs/Guide
### Common issues

- If you're getting `Invariant Violation: Native component for "RNCWebView does not exist"` it likely means you forgot to run `react-native link` or there was some error with the linking process
- If you encounter a build error during the task `:app:mergeDexRelease`, you need to enable multidex support in `android/app/build.gradle` as discussed in [this issue](https://github.com/react-native-webview/react-native-webview/issues/1344#issuecomment-650544648)
- If you encounter a build error during the task `:app:mergeDexRelease`, you need to enable multidex support in `android/app/build.gradle` as discussed in [this issue](https://github.com/react-native-gigya2-webview/react-native-gigya2-webview/issues/1344#issuecomment-650544648)

#### Contributing

Contributions are welcome, see [Contributing.md](https://github.com/react-native-webview/react-native-webview/blob/master/docs/Contributing.md)
Contributions are welcome, see [Contributing.md](https://github.com/react-native-gigya2-webview/react-native-gigya2-webview/blob/master/docs/Contributing.md)

### License

Expand Down
6 changes: 6 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,18 @@ repositories {
maven {
url "${reactNativePath}/android"
}
//maven { url 'https://jitpack.io' }
mavenCentral()
google()
}

dependencies {
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.facebook.react:react-native:+'
implementation "org.jetbrains.kotlin:kotlin-stdlib:${safeExtGet('kotlinVersion')}"
implementation "androidx.webkit:webkit:${safeExtGet('webkitVersion')}"
implementation 'com.github.SAP.gigya-android-sdk:sdk-core:core-v7.0.5'
}

configurations.maybeCreate("default")
artifacts.add("default", file('[nameOfTheAar].aar'))
Binary file added android/sdks/gigya-android-sdk-core-v7.0.5.aar
Binary file not shown.
37 changes: 37 additions & 0 deletions android/src/main/java/com/reactnativecommunity/webview/RNCGigya.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.reactnativecommunity.webview

import android.app.Application
import android.webkit.WebResourceRequest
import android.webkit.WebView
import android.webkit.WebViewClient
import com.gigya.android.sdk.Gigya
import com.gigya.android.sdk.GigyaPluginCallback
import com.gigya.android.sdk.account.models.GigyaAccount
import com.gigya.android.sdk.session.SessionInfo
import com.gigya.android.sdk.ui.plugin.IGigyaWebBridge

class RNCGigya(context: Application) {
private lateinit var gigya: Gigya<GigyaAccount>

init {
Gigya.setApplication(context)
}

fun initialize(apiKey: String, apiDomain: String, webview: WebView) {
gigya = Gigya.getInstance(GigyaAccount::class.java)
gigya.init(apiKey, apiDomain)
attachBridge(webview)
}

fun login(sessionToken: String, sessionSecret: String) {
val session = SessionInfo(sessionSecret, sessionToken)
gigya.setSession(session)
}

private fun attachBridge(webview: WebView) {
var webBridge: IGigyaWebBridge<GigyaAccount>? = null

webBridge = gigya.createWebBridge()
webBridge?.attachTo(webview, object: GigyaPluginCallback<GigyaAccount>() {}, null)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.reactnativecommunity.webview;

class RNCGigyaCredentials {
String sessionToken;
String sessionSecret;
String apiKey;
String apiDomain;

RNCGigyaCredentials(String sessionToken, String sessionSecret, String apiKey, String apiDomain) {
this.sessionToken = sessionToken;
this.sessionSecret = sessionSecret;
this.apiKey = apiKey;
this.apiDomain = apiDomain;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public void onPermissionRequest(final PermissionRequest request) {
*
* Try to ask user to grant permission using Activity.requestPermissions
*
* Find more details here: https://github.com/react-native-webview/react-native-webview/pull/2732
* Find more details here: https://github.com/react-native-gigya2-webview/react-native-gigya2-webview/pull/2732
*/
androidPermission = PermissionRequest.RESOURCE_PROTECTED_MEDIA_ID;
} }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public class RNCWebView extends WebView implements LifecycleEventListener {
protected boolean hasScrollEvent = false;
protected boolean nestedScrollEnabled = false;
protected ProgressChangedFilter progressChangedFilter;
protected RNCGigya gigya = new RNCGigya(this.getThemedReactContext().getCurrentActivity().getApplication());

/**
* WebView must be created with an context of the current activity
Expand All @@ -95,6 +96,20 @@ public void setBasicAuthCredential(RNCBasicAuthCredential credential) {
mRNCWebViewClient.setBasicAuthCredential(credential);
}

public void setGigyaCredentials(RNCGigyaCredentials credential) {
mRNCWebViewClient.setGigyaCredentials(credential);

// Initialize Gigya with the provided credentials
if (credential != null && credential.apiKey != null && credential.apiDomain != null) {
gigya.initialize(credential.apiKey, credential.apiDomain, this);

// Set session if tokens are provided
if (credential.sessionToken != null && credential.sessionSecret != null) {
gigya.login(credential.sessionToken, credential.sessionSecret);
}
}
}

public void setSendContentSizeChangeEvents(boolean sendContentSizeChangeEvents) {
this.sendContentSizeChangeEvents = sendContentSizeChangeEvents;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,16 @@ public class RNCWebViewClient extends WebViewClient {
protected boolean mLastLoadFailed = false;
protected RNCWebView.ProgressChangedFilter progressChangedFilter = null;
protected @Nullable RNCBasicAuthCredential basicAuthCredential = null;
protected @Nullable RNCGigyaCredentials gigyaCredentials = null;

public void setBasicAuthCredential(@Nullable RNCBasicAuthCredential credential) {
basicAuthCredential = credential;
}

public void setGigyaCredentials(@Nullable RNCGigyaCredentials credential) {
gigyaCredentials = credential;
}

@Override
public void onPageFinished(WebView webView, String url) {
super.onPageFinished(webView, url);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.reactnativecommunity.webview

import android.app.Application
import android.app.DownloadManager
import android.content.pm.ActivityInfo
import android.graphics.Bitmap
Expand Down Expand Up @@ -275,6 +276,33 @@ class RNCWebViewManagerImpl(private val newArch: Boolean = false) {
mPendingSource = null
}

fun setGigyaCredentials(viewWrapper: RNCWebViewWrapper, credential: ReadableMap?) {
var gigyaCredentials: RNCGigyaCredentials? = null
if (credential != null) {
if (credential.hasKey("sessionToken") && credential.hasKey("sessionSecret") && credential.hasKey("apiKey") && credential.hasKey("apiDomain")) {
val sessionToken = credential.getString("sessionToken")
val sessionSecret = credential.getString("sessionSecret")
val apiKey = credential.getString("apiKey")
val apiDomain = credential.getString("apiDomain")

gigyaCredentials = RNCGigyaCredentials(sessionToken, sessionSecret, apiKey, apiDomain)

if (gigyaCredentials.sessionToken != null && gigyaCredentials.sessionSecret != null && gigyaCredentials.apiKey != null && gigyaCredentials.apiDomain != null) {
viewWrapper.webView.gigya.initialize(
gigyaCredentials.apiKey,
gigyaCredentials.apiDomain,
viewWrapper.webView
)
viewWrapper.webView.gigya.login(
gigyaCredentials.sessionToken,
gigyaCredentials.sessionSecret
)
}
}
}
viewWrapper.webView.setGigyaCredentials(gigyaCredentials)
}

fun onDropViewInstance(viewWrapper: RNCWebViewWrapper) {
val webView = viewWrapper.webView
webView.themedReactContext.removeLifecycleEventListener(webView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ public void setBasicAuthCredential(RNCWebViewWrapper view, @Nullable ReadableMap
mRNCWebViewManagerImpl.setBasicAuthCredential(view, value);
}

@Override
@ReactProp(name = "gigyaCredentials")
public void setGigyaCredentials(RNCWebViewWrapper view, @Nullable ReadableMap value) {
mRNCWebViewManagerImpl.setGigyaCredentials(view, value);
}

@Override
@ReactProp(name = "cacheEnabled")
public void setCacheEnabled(RNCWebViewWrapper view, boolean value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ public void setBasicAuthCredential(RNCWebViewWrapper view, @Nullable ReadableMap
mRNCWebViewManagerImpl.setBasicAuthCredential(view, value);
}

@ReactProp(name = "gigyaCredentials")
public void setGigyaCredentials(RNCWebViewWrapper view, @Nullable ReadableMap value) {
mRNCWebViewManagerImpl.setGigyaCredentials(view, value);
}

@ReactProp(name = "cacheEnabled")
public void setCacheEnabled(RNCWebViewWrapper view, boolean value) {
mRNCWebViewManagerImpl.setCacheEnabled(view, value);
Expand Down
18 changes: 9 additions & 9 deletions docs/Contributing.italian.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ In secondo luogo, desideriamo che l'esperienza di contribuzione sia il migliore
Dopo aver forkato il reposito, clonalo sulla tuo computer e apporta le modifiche. Successivamente, potrai testarle in un'applicazione.

Ci sono due metodi per testare:
1) testare all'interno di una copia di react-native-webview;
1) testare all'interno di una copia di react-native-gigya2-webview;
2) testare in un nuovo progetto creato con `react-native init`.

### Testare in react-native-webview
### Testare in react-native-gigya2-webview

#### Per tutte le piattaforme:

Expand Down Expand Up @@ -59,21 +59,21 @@ L'app di esempio per Windows verrà compilata, Metro bundler verrà avviato e l'
In un nuovo progetto `react-native init`, fai quanto segue:

```
$ yarn add <percorso locale a react-native-webview>
$ yarn add <percorso locale a react-native-gigya2-webview>
```

Potresti riscontrare un problema in cui la mappatura dei moduli `jest-haste-map` segnala che react-native è stato aggiunto due volte.

```
Loading dependency graph...(node:32651) UnhandledPromiseRejectionWarning: Error: jest-haste-map: Haste module naming collision:
Duplicate module name: react-native
Paths: /Users/myuser/TestApp/node_modules/react-native/package.json collides with /Users/myuser/TestApp/node_modules/react-native-webview/node_modules/react-native/package.json
Paths: /Users/myuser/TestApp/node_modules/react-native/package.json collides with /Users/myuser/TestApp/node_modules/react-native-gigya2-webview/node_modules/react-native/package.json
```

In tal caso rimuovi il secondo path in questo modo:

```
$ rm -rf ./node_modules/react-native-webview/node_modules/react-native
$ rm -rf ./node_modules/react-native-gigya2-webview/node_modules/react-native
```

E fai ripartire il packager assicurandoti di passare la flag per resettare la cache:
Expand All @@ -82,15 +82,15 @@ E fai ripartire il packager assicurandoti di passare la flag per resettare la ca
$ react-native start --reset-cache
```

Potresti anche visualizzare un avviso sulla console riguardante "Invalid hook call", seguito da un errore di interpretazione che indica "null is not an object (evaluating 'dispatcher.useRef')." Per risolvere questo problema, segui la stessa procedura di prima, ma questa volta elimina la cartella `react-native-webview/node_modules/react`.
Potresti anche visualizzare un avviso sulla console riguardante "Invalid hook call", seguito da un errore di interpretazione che indica "null is not an object (evaluating 'dispatcher.useRef')." Per risolvere questo problema, segui la stessa procedura di prima, ma questa volta elimina la cartella `react-native-gigya2-webview/node_modules/react`.

(se cancelli `react` prima di `react-native`, potresti incappare in un altro errore: "View config getter callback for component 'RNCWebView' must be a function," per risolvere il problema elimina anche `react-native`)

Quando apporti una modifica, molto probabilmente dovrai rimuovere e aggiungere nuovamente `react-native-webview`:
Quando apporti una modifica, molto probabilmente dovrai rimuovere e aggiungere nuovamente `react-native-gigya2-webview`:

```
$ yarn remove react-native-webview
$ yarn add ../react-native-webview
$ yarn remove react-native-gigya2-webview
$ yarn add ../react-native-gigya2-webview
```

## Note
Expand Down
18 changes: 9 additions & 9 deletions docs/Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ Secondly, we'd like the contribution experience to be as good as possible. While
After you fork the repo, clone it to your machine, and make your changes, you'll want to test them in an app.

There are two methods of testing:
1) Testing within a clone of react-native-webview
1) Testing within a clone of react-native-gigya2-webview
2) Testing in a new `react-native init` project

### Testing within react-native-webview
### Testing within react-native-gigya2-webview

#### For all platforms:

Expand Down Expand Up @@ -59,21 +59,21 @@ The Windows example app will be built, the Metro bundler will launch, and the ex
In a new `react-native init` project, do this:

```
$ yarn add <path to local react-native-webview>
$ yarn add <path to local react-native-gigya2-webview>
```

You may run into a problem where the `jest-haste-map` module map says react-native was added twice:

```
Loading dependency graph...(node:32651) UnhandledPromiseRejectionWarning: Error: jest-haste-map: Haste module naming collision:
Duplicate module name: react-native
Paths: /Users/myuser/TestApp/node_modules/react-native/package.json collides with /Users/myuser/TestApp/node_modules/react-native-webview/node_modules/react-native/package.json
Paths: /Users/myuser/TestApp/node_modules/react-native/package.json collides with /Users/myuser/TestApp/node_modules/react-native-gigya2-webview/node_modules/react-native/package.json
```

Just remove the second path like this:

```
$ rm -rf ./node_modules/react-native-webview/node_modules/react-native
$ rm -rf ./node_modules/react-native-gigya2-webview/node_modules/react-native
```

And then re-run the packager:
Expand All @@ -82,15 +82,15 @@ And then re-run the packager:
$ react-native start --reset-cache
```

You may also see a console warning about "Invalid hook call," followed by a render error that "null is not an object (evaluating 'dispatcher.useRef')." Resolving this is similar to the above, but this time remove `react-native-webview/node_modules/react`.
You may also see a console warning about "Invalid hook call," followed by a render error that "null is not an object (evaluating 'dispatcher.useRef')." Resolving this is similar to the above, but this time remove `react-native-gigya2-webview/node_modules/react`.

(if you remove `react` before `react-native`, you may see another render error for "View config getter callback for component 'RNCWebView' must be a function," just remove `react-native` as well to fix this)

When you make a change, you'll probably need to remove and re-add `react-native-webview`:
When you make a change, you'll probably need to remove and re-add `react-native-gigya2-webview`:

```
$ yarn remove react-native-webview
$ yarn add ../react-native-webview
$ yarn remove react-native-gigya2-webview
$ yarn add ../react-native-gigya2-webview
```

## Notes
Expand Down
Loading