-
-
Notifications
You must be signed in to change notification settings - Fork 542
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create android binding for addresssheet
- Loading branch information
Remon
committed
Dec 15, 2024
1 parent
02a685b
commit fbfcddf
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...ges/stripe_android/android/src/main/kotlin/com/flutter/stripe/AddressSheetPlatformView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
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) { | ||
|
||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
...droid/android/src/main/kotlin/com/flutter/stripe/StripeAddressSheetPlatformViewFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
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.") | ||
} | ||
return AddressSheetPlatformView(context,channel,viewId, creationParams, addresSheetViewManager, sdkAccessor) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters