Skip to content

How to Use the Library

This guide explains how to use the Bagisto Native Android library with Hotwire Native.

Integration Overview

Package Structure

The library uses these key imports:

kotlin
// Bridge component registration
import com.mobikul.bagisto.utils.CustomBridgeComponents

// Hotwire Native core
import dev.hotwire.core.bridge.KotlinXJsonConverter
import dev.hotwire.core.config.Hotwire
import dev.hotwire.navigation.config.registerBridgeComponents
import dev.hotwire.navigation.activities.HotwireActivity
import dev.hotwire.navigation.navigator.NavigatorConfiguration

Application Setup

The Application class registers all bridge components:

kotlin
class HotwireApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        
        // Register all bagisto bridge components
        Hotwire.registerBridgeComponents(
            *CustomBridgeComponents.all
        )
        
        // Configure JSON converter
        Hotwire.config.jsonConverter = KotlinXJsonConverter()
    }
}

MainActivity Configuration

Extend HotwireActivity for full Hotwire Native integration:

kotlin
class MainActivity : HotwireActivity() {
    
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }

    override fun navigatorConfigurations(): List<NavigatorConfiguration> {
        return listOf(
            NavigatorConfiguration(
                name = "main",
                startLocation = "https://your-storefront.com",
                navigatorHostId = R.id.main_nav_host
            )
        )
    }
}

Bridge Components Available

The library provides these components via CustomBridgeComponents.all:

ComponentDescription
AlertComponentNative alert dialogs
ToastComponentNative toast messages
LocationComponentGPS location services
HapticComponentVibration feedback
BarcodeScannerComponentQR/barcode scanning
ImageSearchComponentML-powered image search
SearchComponentNative search UI
ThemeComponentTheme switching
MenuComponentNavigation menu
FormComponentNative form handling
DownloadComponentFile downloads
ReviewPromptComponentApp review prompts
ShareComponentNative share sheet
NavigationHistoryComponentBack/forward navigation

Custom Component Registration

To register individual components:

kotlin
Hotwire.registerBridgeComponents(
    AlertComponent(context),
    ToastComponent(context),
    LocationComponent(context)
)

Next Steps

Released under the MIT License.