by Joe Masilotti, the Hotwire Native guy
Hotwire Native enables seamless communication between native Swift and Kotlin code and web views in hybrid mobile apps. Bridge components extend this functionality by providing reusable native components that interact your web views. They enable developers to break out of the web view container and drive native features.
This repository contains generalized, production-ready bridge components extracted from real-world client projects. Once configured, each component can be added to any page of your app and customized with a bit of HTML.
- Hotwire Native iOS v1.2 or later
- Hotwire Native Android v1.0 or later
- Hotwire Native Bridge on the web
The source code for the iOS, Android, and web components are included in this repo.
Displays a native alert dialog to confirm an action.
Adds a native button to the navigation bar on iOS and action bar on Android. The button can contain either a text string or an image.
Replaces a form's submit <button>
with a native one that disables during submission.
Vibrate the device via the haptic engine.
Adds a native button to the navigation bar that, when tapped, renders a native menu powered by UIMenu
on iOS and DropdownMenu
on Android.
Prompts the user for a review on the App Store on iOS and Google Play on Android.
Adds a button that presents a native share sheet.
Render a native, floating message that disappears after a few seconds.
Important
Gain access to these components by purchasing a Pro license. This is a one-time payment and not a subscription. It includes access to all bridge components available today, plus all future updates. View the full pro license before purchasing.
Presents a camera that scans barcodes and QR codes using a native camera capture.
Presents a camera that digitizes physical documents.
Prompts the user for their precise location with a single system dialog.
Gets the user's push notification token.
Gets the status of the user's granted permissions, like location and push notifications.
To use a bridge component, copy the relevant Swift/Kotlin and JavaScript files from the components/
directory into your project and register the component.
Check the examples directoy for full working example iOS, Android, and Rails apps.
- Copy the Swift file (
ExampleComponent.swift
) into your Xcode project. - Register the component in
AppDelegate.swift
.
import HotwireNative
import UIKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
Hotwire.registerBridgeComponents([
ExampleComponent.self
])
return true
}
}
- Copy the Kotlin file (
ExampleComponent.kt
) into your Android Studio project. - Register the component inside your
Application
subclass.
package com.masilotti.demo // Change to your package name.
import android.app.Application
import com.masilotti.demo.components.ExampleComponent // Import component here.
import dev.hotwire.core.bridge.BridgeComponentFactory
import dev.hotwire.core.bridge.KotlinXJsonConverter
import dev.hotwire.core.config.Hotwire
import dev.hotwire.navigation.config.registerBridgeComponents
class DemoApplication : Application() {
override fun onCreate() {
super.onCreate()
Hotwire.registerBridgeComponents(
BridgeComponentFactory("example", ::ExampleComponent)
)
}
}
- Copy the JavaScript file (
example_controller.js
) intoapp/javascript/controllers/bridge/
. - Import and initialize (if you aren't dynamically importing Stimulus controllers).
import { application } from "./application"
import Bridge__ExampleController from "./bridge/example_controller"
application.register("bridge--example", Bridge__ExampleController)
- Hotwire Native Android
- Jetpack Compose
- A serialization library, like kotlinx.serialization
- Material Symbol font if using images
- Unzip the downloaded font and copy the Outlined version
.ttf
toapp/src/main/res/font/material_symbols.ttf
- Unzip the downloaded font and copy the Outlined version
Once installed, use a component by adding a data-controller
attribute that matches the name of the Stimulus controller.
<div data-controller="bridge--example"></div>
Each component can then be configured further - check the README in each component's directory for more information.
If you need help installing, configuring, or using the components, feel free to open a new discussion or send me an email. I'd love to help!