Developers attach path handlers to the Web Frame for handling web view requests. Path handlers are usually used for providing assets and resources to the web view.
Path handlers must adhere to the first-party
WebViewAssetLoader.PathHandler
interface.
One particularly useful subclass is
WebViewAssetLoader.InternalStoragePathHandler
,
which serves static files from almost any directory on the native device.
Peregrine constructs its own
WebViewAssetLoader
from the provided path→PathHandler
map.
Examples
In the following example, the /photos/
path is being registered and linked to
a directory on the native device.
val photosDir = context.filesDir.resolve("photos")
photosDir.mkdirs()
val configuration = WebFrame.Configuration(
baseUrl = ...
functions = ...
observables = ...
pathHandlers = mapOf(
"/photos/" to WebViewAssetLoader.InternalStoragePathHandler(
context,
photosDir
)
),
)
Kotlin API
WebViewAssetLoader.InternalStoragePathHandler
See the official documentation for this class.
WebViewAssetLoader.PathHandler
See the official documentation for this interface.
WebResourceResponse
See the official documentation for this class.