package com.checkoutreactnativecomponents.components.managers import com.checkoutreactnativecomponents.utils.Constants import com.checkoutreactnativecomponents.utils.ReadableMapUtils import com.facebook.react.bridge.ReadableMap import com.facebook.react.uimanager.SimpleViewManager import com.facebook.react.uimanager.ThemedReactContext import com.facebook.react.uimanager.ViewManagerDelegate import com.facebook.react.uimanager.annotations.ReactProp /** * Abstract base class for React Native view managers that handle checkout components. * * Provides common functionality for: * - Configuration prop handling * - View creation lifecycle * - Event type constants * * @param T The view type this manager handles */ public abstract class BaseCheckoutManager : SimpleViewManager() { /** * Returns the name of this view manager for React Native registration. */ abstract override fun getName(): String /** * Creates a new instance of the view this manager handles. */ abstract override fun createViewInstance(context: ThemedReactContext): T /** * Handles the config prop that is common to all checkout components. * Converts ReadableMap to HashMap and delegates to the view's setConfig method. */ @ReactProp(name = "config") public open fun setConfig(view: T?, value: ReadableMap?) { val config = ReadableMapUtils.readableMapToHashMap(value) setConfigOnView(view, config) } /** * Abstract method to set the configuration on the specific view type. * Implementations should cast the view to their specific type and call setConfig. */ protected abstract fun setConfigOnView(view: T?, config: HashMap) /** * Returns the exported custom direct event type constants. * Override this to add component-specific events. */ override fun getExportedCustomDirectEventTypeConstants(): MutableMap? = getDefaultEventConstants() /** * Returns the default event constants that most checkout components need. * Components can override getExportedCustomDirectEventTypeConstants to add more events. */ protected open fun getDefaultEventConstants(): MutableMap = mutableMapOf( Constants.ON_DIMENSIONS_CHANGED to mapOf("registrationName" to Constants.ON_DIMENSIONS_CHANGED) ) }