Skip to content

Commit

Permalink
feat: create android binding for addresssheet
Browse files Browse the repository at this point in the history
  • Loading branch information
Remon committed Dec 15, 2024
1 parent 02a685b commit fbfcddf
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.flutter.stripe

import android.content.Context
import android.view.View
import com.facebook.react.uimanager.ThemedReactContext

Check warning on line 5 in packages/stripe_android/android/src/main/kotlin/com/flutter/stripe/AddressSheetPlatformView.kt

View workflow job for this annotation

GitHub Actions / Typo CI

uimanager

"uimanager" is a typo. Did you mean "manager"?
import com.reactnativestripesdk.StripeSdkModule
import com.reactnativestripesdk.addresssheet.AddressSheetView
import com.reactnativestripesdk.addresssheet.AddressSheetViewManager
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.platform.PlatformView

class AddressSheetPlatformView(
private val context: Context,
private val channel: MethodChannel,
id: Int,
private val creationParams: Map<String?, Any?>?,
private val addressSheetManager: AddressSheetViewManager,
private val sdkAccessor: () -> StripeSdkModule

) : PlatformView, MethodChannel.MethodCallHandler {
private val themedContext = ThemedReactContext(sdkAccessor().reactContext, channel, sdkAccessor)


lateinit var addressSheetView: AddressSheetView

init {

addressSheetView = addressSheetManager.createViewInstance(themedContext)
channel.setMethodCallHandler(this)
}

override fun getView(): View? {
return addressSheetView
}

override fun dispose() {
addressSheetManager.onDropViewInstance(addressSheetView)
}

override fun onFlutterViewAttached(flutterView: View) {
addressSheetManager.onAfterUpdateTransaction(addressSheetView)
}

override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.flutter.stripe

import android.content.Context
import com.reactnativestripesdk.StripeSdkModule
import com.reactnativestripesdk.addresssheet.AddressSheetViewManager
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.StandardMessageCodec
import io.flutter.plugin.platform.PlatformView
import io.flutter.plugin.platform.PlatformViewFactory

class StripeAddressSheetPlatformViewFactory(
private val flutterPluginBinding: FlutterPlugin.FlutterPluginBinding,
private val addresSheetViewManager: AddressSheetViewManager,

Check warning on line 14 in packages/stripe_android/android/src/main/kotlin/com/flutter/stripe/StripeAddressSheetPlatformViewFactory.kt

View workflow job for this annotation

GitHub Actions / Typo CI

addresSheetViewManager

"addresSheetViewManager" is a typo. Did you mean "addersSheetViewManager"?
private val sdkAccessor: () -> StripeSdkModule
) : PlatformViewFactory(StandardMessageCodec.INSTANCE) {

override fun create(context: Context?, viewId: Int, args: Any?): PlatformView {
val channel = MethodChannel(flutterPluginBinding.binaryMessenger, "flutter.stripe/address_sheet/${viewId}")
val creationParams = args as? Map<String?, Any?>?
if(context == null){
throw AssertionError("Context is not allowed to be null when launching aubecs view.")

Check warning on line 22 in packages/stripe_android/android/src/main/kotlin/com/flutter/stripe/StripeAddressSheetPlatformViewFactory.kt

View workflow job for this annotation

GitHub Actions / Typo CI

aubecs

"aubecs" is a typo. Did you mean "because"?
}
return AddressSheetPlatformView(context,channel,viewId, creationParams, addresSheetViewManager, sdkAccessor)

Check warning on line 24 in packages/stripe_android/android/src/main/kotlin/com/flutter/stripe/StripeAddressSheetPlatformViewFactory.kt

View workflow job for this annotation

GitHub Actions / Typo CI

addresSheetViewManager

"addresSheetViewManager" is a typo. Did you mean "addersSheetViewManager"?
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.facebook.react.uimanager.DisplayMetricsHolder
import com.facebook.react.uimanager.ThemedReactContext
import com.google.android.material.internal.ThemeEnforcement
import com.reactnativestripesdk.*
import com.reactnativestripesdk.addresssheet.AddressSheetViewManager
import com.reactnativestripesdk.pushprovisioning.AddToWalletButtonManager
import io.flutter.embedding.android.FlutterFragmentActivity
import io.flutter.embedding.engine.plugins.FlutterPlugin
Expand Down Expand Up @@ -49,6 +50,10 @@ class StripeAndroidPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
AuBECSDebitFormViewManager()
}

private val addressSheetFormViewManager: AddressSheetViewManager by lazy {
AddressSheetViewManager()
}

override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(flutterPluginBinding.applicationContext)

Expand All @@ -69,6 +74,7 @@ class StripeAndroidPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
flutterPluginBinding
.platformViewRegistry
.registerViewFactory("flutter.stripe/add_to_wallet", StripeAddToWalletPlatformViewFactory(flutterPluginBinding, AddToWalletButtonManager(flutterPluginBinding.applicationContext)){stripeSdk})
flutterPluginBinding.platformViewRegistry.registerViewFactory("flutter.stripe/address_sheet", StripeAddressSheetPlatformViewFactory(flutterPluginBinding, addressSheetFormViewManager ){stripeSdk})
}

override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
Expand Down

0 comments on commit fbfcddf

Please sign in to comment.