diff --git a/.gitignore b/.gitignore index 65f294f..3a0048f 100644 --- a/.gitignore +++ b/.gitignore @@ -69,7 +69,6 @@ android/keystores/debug.keystore !.yarn/versions # Expo -.expo/ # Turborepo .turbo/ @@ -81,4 +80,7 @@ lib/ ios/generated android/generated -.env \ No newline at end of file +.env +/package-lock.json +/example/package-lock.json +/example/Gemfile.lock diff --git a/android/build.gradle b/android/build.gradle index e276ab2..54e7723 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,19 +1,3 @@ -buildscript { - // Buildscript is evaluated before everything else so we can't use getExtOrDefault - def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["WebIdMetaPlugin_kotlinVersion"] - - repositories { - google() - mavenCentral() - } - - dependencies { - classpath "com.android.tools.build:gradle:7.2.1" - // noinspection DifferentKotlinGradleVersion - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - } -} - def reactNativeArchitectures() { def value = rootProject.getProperties().get("reactNativeArchitectures") return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"] @@ -26,10 +10,6 @@ def isNewArchitectureEnabled() { apply plugin: "com.android.library" apply plugin: "kotlin-android" -if (isNewArchitectureEnabled()) { - apply plugin: "com.facebook.react" -} - def getExtOrDefault(name) { return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["WebIdMetaPlugin_" + name] } @@ -82,18 +62,35 @@ android { } } -repositories { - mavenCentral() - google() -} - def kotlin_version = getExtOrDefault("kotlinVersion") dependencies { // For < 0.71, this will be from the local maven repo // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin //noinspection GradleDynamicVersion - implementation "com.facebook.react:react-native:+" - implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + implementation "com.google.code.gson:gson:2.10.1" + + implementation("com.facebook.react:react-android") + def product_catalog_version = "15.3.0" + + implementation ("de.webid-solutions:android_meta_plugin:$product_catalog_version") { + changing = true + } + + implementation ("de.webid-solutions:android_auto_ident_on_server_product_plugin:$product_catalog_version") { + changing = true + } + + implementation ("de.webid-solutions:android_pay_on_server_product_plugin:$product_catalog_version") { + changing = true + } + + implementation ("de.webid-solutions:android_video_ident_product_plugin:$product_catalog_version") { + changing = true + } + + implementation ("de.webid-solutions:android_eid_on_server_product_plugin:$product_catalog_version") { + changing = true + } } diff --git a/android/gradle.properties b/android/gradle.properties index 46a50c9..4d64b21 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1,4 +1,4 @@ -WebIdMetaPlugin_kotlinVersion=1.7.0 +WebIdMetaPlugin_kotlinVersion=2.1.20 WebIdMetaPlugin_minSdkVersion=21 WebIdMetaPlugin_targetSdkVersion=31 WebIdMetaPlugin_compileSdkVersion=31 diff --git a/android/settings.gradle b/android/settings.gradle new file mode 100644 index 0000000..20fbcc9 --- /dev/null +++ b/android/settings.gradle @@ -0,0 +1,11 @@ +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + + maven { + url 'https://api.webid-solutions.de/releases/android/maven/repository/internal' + } + } +} diff --git a/android/src/main/java/com/webidmetaplugin/WebIdMetaPluginModule.kt b/android/src/main/java/com/webidmetaplugin/WebIdMetaPluginModule.kt index 5288405..62b02f2 100644 --- a/android/src/main/java/com/webidmetaplugin/WebIdMetaPluginModule.kt +++ b/android/src/main/java/com/webidmetaplugin/WebIdMetaPluginModule.kt @@ -1,25 +1,227 @@ package com.webidmetaplugin +import android.content.Intent +import androidx.activity.result.ActivityResultLauncher +import androidx.activity.result.contract.ActivityResultContracts +import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentActivity +import com.facebook.react.bridge.Promise import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.bridge.ReactContextBaseJavaModule import com.facebook.react.bridge.ReactMethod -import com.facebook.react.bridge.Promise +import com.facebook.react.bridge.ReadableArray +import com.facebook.react.modules.core.DeviceEventManagerModule +import de.webidsolutions.auto_ident_on_server_product_plugin.AutoIdentOnServerProductPlugin +import de.webidsolutions.eid_on_server_product_plugin.EIdOnServerProductPlugin +import de.webidsolutions.meta_plugin.WebIdMetaPlugin +import de.webidsolutions.mobile_app.sdk.WebIdSdkEnvironment +import de.webidsolutions.pay_on_server_product_plugin.PayOnServerProductPlugin +import de.webidsolutions.plugin_core.IEPluginError +import de.webidsolutions.plugin_core.IProductPluginWebId +import de.webidsolutions.video_ident.plugin.videocall.VideoOptionsConfig +import de.webidsolutions.video_ident_product_plugin.VideoIdentProductPlugin +import java.net.URI +import com.facebook.react.bridge.UiThreadUtil +import android.util.Log +import com.google.gson.Gson -class WebIdMetaPluginModule(reactContext: ReactApplicationContext) : - ReactContextBaseJavaModule(reactContext) { +private const val TAG = "WebIdMetaPlugin" - override fun getName(): String { - return NAME +class WebIdMetaPluginModule( + private val reactContext: ReactApplicationContext +) : ReactContextBaseJavaModule(reactContext) { + + private var metaPlugin: WebIdMetaPlugin? = null + + override fun getName() = "WebIdMetaPlugin" + + private fun sendEvent(eventName: String, data: String) { + reactContext + .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java) + .emit(eventName, data) } - // Example method - // See https://reactnative.dev/docs/native-modules-android + private var listenerCount = 0 + @ReactMethod - fun multiply(a: Double, b: Double, promise: Promise) { - promise.resolve(a * b) + fun addListener(eventName: String) { + listenerCount += 1 } - companion object { - const val NAME = "WebIdMetaPlugin" + @ReactMethod + fun removeListeners(count: Int) { + listenerCount = (listenerCount - count).coerceAtLeast(0) + } + + @ReactMethod + fun createMetaPlugin( + uri: String, + username: String, + apiKey: String, + shaPins: ReadableArray, + plugins: ReadableArray, + promise: Promise + ) { + val cleanUri = uri.trim() + val cleanUsername = username.trim() + val cleanApiKey = apiKey.trim() + + val shaPinsList = shaPins.toArrayList().map { it.toString() } + val pluginsList = plugins.toArrayList().map { it.toString() } + + Log.i(TAG, "createMetaPlugin plugins(raw) len=${pluginsList.size} values=$pluginsList") + + try { + val environment = WebIdSdkEnvironment( + URI.create(cleanUri), + *shaPinsList.toTypedArray() + ) + + val selectedPlugins = ArrayList() + + pluginsList.forEach { p -> + when (p) { + "AutoIdOnServer" -> selectedPlugins.add(AutoIdentOnServerProductPlugin()) + "PayOnServer" -> selectedPlugins.add(PayOnServerProductPlugin()) + "VideoId" -> selectedPlugins.add(VideoIdentProductPlugin(config = VideoOptionsConfig())) + "EIdOnServer" -> selectedPlugins.add(EIdOnServerProductPlugin()) + else -> Log.w(TAG, "createMetaPlugin unknown plugin string='$p'") + } + } + + Log.i(TAG, "createMetaPlugin plugins(mapped) len=${selectedPlugins.size} classes=${selectedPlugins.map { it.javaClass.simpleName }}") + + metaPlugin = WebIdMetaPlugin( + environment, + cleanUsername, + cleanApiKey, + reactApplicationContext, + selectedPlugins + ) + + promise.resolve("MetaPluginCreated") + } catch (e: Exception) { + Log.e(TAG, "createMetaPlugin failed: ${e.message}", e) + promise.reject("CREATE_ERROR", e.message, e) + } + } + + @ReactMethod + fun verifyActionId(actionId: String, promise: Promise) { + Log.i(TAG, "verifyActionId() called actionId=$actionId") + + try { + val plugin = metaPlugin + if (plugin == null) { + Log.w(TAG, "verifyActionId() blocked: SDK_NOT_INITIALIZED") + promise.reject("SDK_NOT_INITIALIZED", "MetaPlugin not created. Call createMetaPlugin() first.") + return + } + + val result = plugin.verify(actionId) + + val json = Gson().toJson(result) + Log.i(TAG, "verifyActionId() success, jsonLen=${json.length}") + + promise.resolve(json) + } catch (e: Exception) { + Log.e(TAG, "verifyActionId() failed: ${e.message}", e) + promise.reject("VERIFY_ERROR", e.message, e) + } + } + + @ReactMethod + fun start(promise: Promise) { + val activity = reactApplicationContext.currentActivity + + if (activity !is FragmentActivity) { + promise.reject("NO_ACTIVITY", "Current activity is not a FragmentActivity") + return + } + + val plugin = metaPlugin + if (plugin == null) { + promise.reject("SDK_NOT_INITIALIZED", "MetaPlugin not created. Call createMetaPlugin() first.") + return + } + + UiThreadUtil.runOnUiThread { + try { + val fragment = WebIdResultHostFragment.getOrCreate( + activity = activity, + onResult = { resultCode, data -> + try { + val result = data?.let { + IProductPluginWebId.getProductPluginResult(it, resultCode) + } + + if (result?.error == null) { + sendEvent("WebIdSdkEvent.finishedSuccess", result?.info ?: "") + } else { + sendEvent("WebIdSdkEvent.finishedFailed", result.error.toString()) + } + } catch (e: Exception) { + sendEvent("WebIdSdkEvent.finishedFailed", e.message ?: "Unknown") + } + } + ) + + val customTheme: Int? = null + + plugin.startPlugin( + activity, + fragment.launcher, + customTheme + ) + + promise.resolve("PluginStarted") + } catch (e: Exception) { + promise.reject("START_ERROR", e.message, e) + } + } + } + + class WebIdResultHostFragment : Fragment() { + + private var onResult: ((resultCode: Int, data: Intent?) -> Unit)? = null + + lateinit var launcher: ActivityResultLauncher + private set + + override fun onCreate(savedInstanceState: android.os.Bundle?) { + super.onCreate(savedInstanceState) + + launcher = + registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> + onResult?.invoke(result.resultCode, result.data) + } + } + + companion object { + private const val TAG = "WebIdResultHostFragment" + + fun getOrCreate( + activity: FragmentActivity, + onResult: (resultCode: Int, data: Intent?) -> Unit + ): WebIdResultHostFragment { + val fm = activity.supportFragmentManager + + val existing = fm.findFragmentByTag(TAG) as? WebIdResultHostFragment + if (existing != null) { + existing.onResult = onResult + return existing + } + + val fragment = WebIdResultHostFragment().apply { + this.onResult = onResult + } + + fm.beginTransaction() + .add(fragment, TAG) + .commitNowAllowingStateLoss() + + return fragment + } + } } } diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index c2ca9d8..bf80a8e 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -1,6 +1,8 @@ -apply plugin: "com.android.application" -apply plugin: "org.jetbrains.kotlin.android" -apply plugin: "com.facebook.react" +plugins { + id("com.android.application") + id("org.jetbrains.kotlin.android") + id("com.facebook.react") +} /** * This is the configuration block to customize your React Native Android app. @@ -75,15 +77,18 @@ def jscFlavor = 'org.webkit:android-jsc:+' android { ndkVersion rootProject.ext.ndkVersion buildToolsVersion rootProject.ext.buildToolsVersion - compileSdk rootProject.ext.compileSdkVersion + compileSdk 35 - namespace "webidmetaplugin.example" + + namespace "webidmetaplugin.example" defaultConfig { applicationId "webidmetaplugin.example" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion versionCode 1 versionName "1.0" + buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", (project.hasProperty("newArchEnabled") ? project.getProperty("newArchEnabled") : "false") + } signingConfigs { debug { diff --git a/example/android/app/src/main/java/webidmetaplugin/example/MainApplication.kt b/example/android/app/src/main/java/webidmetaplugin/example/MainApplication.kt index ff257d3..6a78e73 100644 --- a/example/android/app/src/main/java/webidmetaplugin/example/MainApplication.kt +++ b/example/android/app/src/main/java/webidmetaplugin/example/MainApplication.kt @@ -9,34 +9,36 @@ import com.facebook.react.ReactPackage import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost import com.facebook.react.defaults.DefaultReactNativeHost +import com.facebook.react.soloader.OpenSourceMergedSoMapping import com.facebook.soloader.SoLoader +import com.webidmetaplugin.WebIdMetaPluginPackage +import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load class MainApplication : Application(), ReactApplication { override val reactNativeHost: ReactNativeHost = - object : DefaultReactNativeHost(this) { - override fun getPackages(): List = - PackageList(this).packages.apply { - // Packages that cannot be autolinked yet can be added manually here, for example: - // add(MyReactNativePackage()) - } + object : DefaultReactNativeHost(this) { + override fun getPackages(): List = + PackageList(this).packages.apply { + add(WebIdMetaPluginPackage()) + } - override fun getJSMainModuleName(): String = "index" + override fun getJSMainModuleName(): String = "index" - override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG + override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG - override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED - override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED - } + override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED + + override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED + } override val reactHost: ReactHost get() = getDefaultReactHost(applicationContext, reactNativeHost) override fun onCreate() { super.onCreate() - SoLoader.init(this, false) + SoLoader.init(this, OpenSourceMergedSoMapping) if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { - // If you opted-in for the New Architecture, we load the native entry point for this app. load() } } diff --git a/example/android/build.gradle b/example/android/build.gradle index df1ce4d..17b236f 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,21 +1,20 @@ buildscript { - ext { - buildToolsVersion = "34.0.0" - minSdkVersion = 23 - compileSdkVersion = 34 - targetSdkVersion = 34 - ndkVersion = "26.1.10909125" - kotlinVersion = "1.9.24" - } - repositories { - google() - mavenCentral() - } - dependencies { - classpath("com.android.tools.build:gradle") - classpath("com.facebook.react:react-native-gradle-plugin") - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin") - } -} + ext { + buildToolsVersion = "35.0.0" + minSdkVersion = 28 + compileSdkVersion = 35 + targetSdkVersion = 35 + ndkVersion = "26.1.10909125" + kotlinVersion = "2.1.20" + } -apply plugin: "com.facebook.react.rootproject" + repositories { + google() + mavenCentral() + } + + dependencies { + classpath("com.android.tools.build:gradle:8.6.0") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.1.20") + } +} diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index 6f7a6eb..ed4c299 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-all.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/example/android/settings.gradle b/example/android/settings.gradle index 29ea29f..cbd36e6 100644 --- a/example/android/settings.gradle +++ b/example/android/settings.gradle @@ -1,6 +1,43 @@ -pluginManagement { includeBuild("../node_modules/@react-native/gradle-plugin") } -plugins { id("com.facebook.react.settings") } -extensions.configure(com.facebook.react.ReactSettingsExtension){ ex -> ex.autolinkLibrariesFromCommand() } -rootProject.name = 'webidmetaplugin.example' -include ':app' -includeBuild('../node_modules/@react-native/gradle-plugin') +pluginManagement { + repositories { + gradlePluginPortal() + google() + mavenCentral() + } + + resolutionStrategy { + eachPlugin { + if (requested.id.id == "org.jetbrains.kotlin.android") { + useVersion("2.1.20") + } + if (requested.id.id == "org.jetbrains.kotlin.jvm") { + useVersion("2.1.20") + } + } + } + + includeBuild("../node_modules/@react-native/gradle-plugin") +} + +plugins { + id("com.facebook.react.settings") +} + +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS) + repositories { + google() + mavenCentral() + + maven { + url 'https://api.webid-solutions.de/releases/android/maven/repository/internal' + } + } +} + +extensions.configure(com.facebook.react.ReactSettingsExtension) { ex -> + ex.autolinkLibrariesFromCommand() +} + +rootProject.name = "webidmetaplugin.example" +include(":app") diff --git a/example/ios/WebIdMetaPluginExample.xcodeproj/project.pbxproj b/example/ios/WebIdMetaPluginExample.xcodeproj/project.pbxproj index 7cb67dc..07256f9 100644 --- a/example/ios/WebIdMetaPluginExample.xcodeproj/project.pbxproj +++ b/example/ios/WebIdMetaPluginExample.xcodeproj/project.pbxproj @@ -53,6 +53,7 @@ 4058D6922F19726100498E39 /* WebIdVideoIdentProductPlugin.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 48F71C442C80D0DF00BD6B5D /* WebIdVideoIdentProductPlugin.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 6DE0A3D7B22BC1FF2E727057 /* libPods-WebIdMetaPluginExample-WebIdMetaPluginExampleTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4685DC1BED0D20ECAC1ED4EC /* libPods-WebIdMetaPluginExample-WebIdMetaPluginExampleTests.a */; }; 81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; }; + B5ABC6AE66EFC36DA14A4175 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 3A271875C9F09281B4786E72 /* PrivacyInfo.xcprivacy */; }; C88BC4EF9171E4119C4DE09A /* libPods-WebIdMetaPluginExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = A790AFDC34C073FF67478665 /* libPods-WebIdMetaPluginExample.a */; }; /* End PBXBuildFile section */ @@ -106,6 +107,7 @@ 13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = WebIdMetaPluginExample/Images.xcassets; sourceTree = ""; }; 13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = WebIdMetaPluginExample/Info.plist; sourceTree = ""; }; 13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = WebIdMetaPluginExample/main.m; sourceTree = ""; }; + 3A271875C9F09281B4786E72 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; includeInIndex = 1; name = PrivacyInfo.xcprivacy; path = WebIdMetaPluginExample/PrivacyInfo.xcprivacy; sourceTree = ""; }; 40A7A7232F18352D00A4B1CE /* WebIdAutoIdentOnServerProductPlugin.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = WebIdAutoIdentOnServerProductPlugin.xcframework; path = Pods/WebIdAutoIdentOnServerProductPlugin/WebIdAutoIdentOnServerProductPlugin.xcframework; sourceTree = ""; }; 40A7A7262F1835A400A4B1CE /* WebIdEIdOnServerProductPlugin.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = WebIdEIdOnServerProductPlugin.xcframework; path = Pods/WebIdEIdOnServerProductPlugin/WebIdEIdOnServerProductPlugin.xcframework; sourceTree = ""; }; 40A7A7292F1835B400A4B1CE /* WebIdEIdentPlugin.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = WebIdEIdentPlugin.xcframework; path = Pods/WebIdEIdentPlugin/WebIdEIdentPlugin.xcframework; sourceTree = ""; }; @@ -206,6 +208,7 @@ 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */, 13B07FB71A68108700A75B9A /* main.m */, EF15005B197F2F6F6438D520 /* PrivacyInfo.xcprivacy */, + 3A271875C9F09281B4786E72 /* PrivacyInfo.xcprivacy */, ); name = WebIdMetaPluginExample; sourceTree = ""; @@ -377,6 +380,7 @@ files = ( 81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */, 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */, + B5ABC6AE66EFC36DA14A4175 /* PrivacyInfo.xcprivacy in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -733,7 +737,10 @@ "-DFOLLY_CFG_NO_COROUTINES=1", "-DFOLLY_HAVE_CLOCK_GETTIME=1", ); - OTHER_LDFLAGS = "$(inherited) "; + OTHER_LDFLAGS = ( + "$(inherited)", + " ", + ); REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native"; SDKROOT = iphoneos; SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) DEBUG"; @@ -817,7 +824,10 @@ "-DFOLLY_CFG_NO_COROUTINES=1", "-DFOLLY_HAVE_CLOCK_GETTIME=1", ); - OTHER_LDFLAGS = "$(inherited) "; + OTHER_LDFLAGS = ( + "$(inherited)", + " ", + ); REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native"; SDKROOT = iphoneos; USE_HERMES = true; diff --git a/example/package.json b/example/package.json index 060d562..069a7a4 100644 --- a/example/package.json +++ b/example/package.json @@ -10,17 +10,17 @@ "build:ios": "react-native build-ios --scheme WebIdMetaPluginExample --mode Debug --extra-params \"-sdk iphonesimulator CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ GCC_OPTIMIZATION_LEVEL=0 GCC_PRECOMPILE_PREFIX_HEADER=YES ASSETCATALOG_COMPILER_OPTIMIZATION=time DEBUG_INFORMATION_FORMAT=dwarf COMPILER_INDEX_STORE_ENABLE=NO\"" }, "dependencies": { - "react": "18.3.1", - "react-native": "0.75.2", + "react": "19.2.3", + "react-native": "0.84.0", "react-native-bouncy-checkbox": "^4.1.4" }, "devDependencies": { "@babel/core": "^7.20.0", "@babel/preset-env": "^7.20.0", "@babel/runtime": "^7.20.0", - "@react-native/babel-preset": "0.75.2", - "@react-native/metro-config": "0.75.2", - "@react-native/typescript-config": "0.75.2", + "@react-native/babel-preset": "0.84.0", + "@react-native/metro-config": "0.84.0", + "@react-native/typescript-config": "0.84.0", "react-native-builder-bob": "^0.30.0", "react-native-dotenv": "^3.4.9" }, diff --git a/example/src/App.tsx b/example/src/App.tsx index a3fda1c..e2e66cf 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -25,11 +25,20 @@ import BouncyCheckbox from 'react-native-bouncy-checkbox'; export default function App() { const [actionId, onChangeActionId] = React.useState(''); - var selectedPlugins: Set = new Set(); + const [selectedPlugins, setSelectedPlugins] = React.useState([]); + + const togglePlugin = (name: string, isChecked: boolean) => { + setSelectedPlugins((prev) => { + const next = new Set(prev); + if (isChecked) next.add(name); + else next.delete(name); + return Array.from(next); + }); + }; webIdEventEmitter.addListener(WebIdSdkEvent.finishedFailed, (eventData) => { let result = parseJSONToType(eventData); - if (result != undefined) { + if (result !== undefined) { console.log( 'received failed event with result code: ', result.genericResultCode @@ -39,7 +48,7 @@ export default function App() { webIdEventEmitter.addListener(WebIdSdkEvent.finishedSuccess, (eventData) => { let result = parseJSONToType(eventData); - if (result != undefined) { + if (result !== undefined) { console.log( 'received failed event with process finished: ', result.processFinished @@ -48,12 +57,18 @@ export default function App() { }); const styles = StyleSheet.create({ + container: { + paddingHorizontal: 16, + paddingBottom: 16, + paddingTop: 64, + }, input: { height: 40, margin: 12, borderWidth: 1, padding: 10, }, + btn: { marginVertical: 8 }, }); const showAlert = (title: string, message: string) => { @@ -63,13 +78,7 @@ export default function App() { }; const onCreateMetaPlugin = () => { - createMetaPlugin( - URL, - USERNAME, - API_KEY, - [CERT_BASE64], - Array.from(selectedPlugins) - ) + createMetaPlugin(URL, USERNAME, API_KEY, [CERT_BASE64], selectedPlugins) .then((data) => { showAlert('Success', data); }) @@ -119,65 +128,63 @@ export default function App() { }; return ( - + - isChecked === true - ? selectedPlugins.add('AutoIdOnServer') - : selectedPlugins.delete('AutoIdOnServer') + togglePlugin('AutoIdOnServer', isChecked) } /> AutoIdOnServer - isChecked === true - ? selectedPlugins.add('PayOnServer') - : selectedPlugins.delete('PayOnServer') + togglePlugin('PayOnServer', isChecked) } /> PayOnServer - isChecked === true - ? selectedPlugins.add('VideoId') - : selectedPlugins.delete('VideoId') + togglePlugin('VideoId', isChecked) } /> VideoId - isChecked === true - ? selectedPlugins.add('EIdOnServer') - : selectedPlugins.delete('EIdOnServer') + togglePlugin('EIdOnServer', isChecked) } /> EIdOnServer -