Skip to content

Commit

Permalink
Added asset loader example
Browse files Browse the repository at this point in the history
  • Loading branch information
smikhalevski committed Dec 29, 2023
1 parent d377c07 commit 03a5c67
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
13 changes: 13 additions & 0 deletions android/example/src/main/java/com/example/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.Intent
import android.os.Bundle
import android.security.keystore.KeyGenParameterSpec
import android.webkit.CookieManager
import android.webkit.WebResourceResponse
import android.webkit.WebView
import androidx.appcompat.app.AppCompatActivity
import androidx.webkit.WebViewAssetLoader
Expand Down Expand Up @@ -49,6 +50,18 @@ class MainActivity : AppCompatActivity() {
cookieManager.setAcceptThirdPartyCookies(webView, true)

eventBus.register(EventBridge(webView).apply { enable() })
eventBus.register(
// Register multiple instances of this plugin to handle different domains
AssetLoaderPlugin(
this,
WebViewAssetLoader.Builder()
.setDomain("iframe.example.com")
.addPathHandler("/") {
WebResourceResponse("text/html", null, "Hello".byteInputStream())
}
.build()
)
)
eventBus.register(DevicePlugin(this))
eventBus.register(EncryptedStoragePlugin(File(filesDir, "storage"), BuildConfig.APPLICATION_ID.toByteArray()))
eventBus.register(FileChooserPlugin(this, externalCacheDir, "${BuildConfig.APPLICATION_ID}.provider"))
Expand Down
2 changes: 2 additions & 0 deletions web/example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ import { FacebookShareExample } from './examples/FacebookShareExample';
import { DownloadExample } from './examples/DownloadExample';
import { BiometricExample } from './examples/BiometricExample';
import { BiometricEncryptedStorageExample } from './examples/BiometricEncryptedStorageExample';
import { AssetLoaderExample } from './examples/AssetLoaderExample';

export function App() {
return (
<>
<ToastExample />
<AssetLoaderExample />
<BiometricExample />
<BiometricEncryptedStorageExample />
<DownloadExample />
Expand Down
14 changes: 14 additions & 0 deletions web/example/src/examples/AssetLoaderExample.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';

export function AssetLoaderExample() {
return (
<>
<h2>{'Asset loader'}</h2>

<iframe
src="https://iframe.example.com"
style={{ display: 'block' }}
/>
</>
);
}
2 changes: 1 addition & 1 deletion web/example/src/examples/EventBridgeExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function EventBridgeExample() {

return (
<>
<h2>{'EventBridge'}</h2>
<h2>{'Event bridge'}</h2>

<p>
{'Is '}
Expand Down

0 comments on commit 03a5c67

Please sign in to comment.