From ee8617542f5f1d070066835ce3466fdd0cf676cd Mon Sep 17 00:00:00 2001 From: Alessandro Senese Date: Tue, 13 Aug 2024 11:37:33 +0100 Subject: [PATCH 1/6] try to add keyboard support --- .../java/com/reactnativeama/AmaPackage.kt | 9 +-- .../reactnativeama/components/AMAWrapper.kt | 13 ++++ .../components/AMAWrapperManager.kt | 22 +++++++ .../components/AmaFlatListWrapper.kt | 42 ------------- .../components/AmaFlatListWrapperManager.kt | 32 ---------- .../modules/AMAAnimationsStatusModule.kt | 38 ------------ examples/bare/android/build.gradle | 2 - examples/expo/.gitignore | 3 + examples/expo/app.json | 57 +++++++++-------- examples/expo/package.json | 8 +-- packages/core/src/components/AMAProvider.tsx | 35 ++++++----- packages/core/src/components/AMAWrapper.tsx | 16 +++++ packages/lists/src/components/ListWrapper.tsx | 18 ++---- yarn.lock | 62 +++++++++++++++++++ 14 files changed, 176 insertions(+), 181 deletions(-) create mode 100644 android/src/main/java/com/reactnativeama/components/AMAWrapper.kt create mode 100644 android/src/main/java/com/reactnativeama/components/AMAWrapperManager.kt delete mode 100644 android/src/main/java/com/reactnativeama/components/AmaFlatListWrapper.kt delete mode 100644 android/src/main/java/com/reactnativeama/components/AmaFlatListWrapperManager.kt delete mode 100644 android/src/main/java/com/reactnativeama/modules/AMAAnimationsStatusModule.kt create mode 100644 packages/core/src/components/AMAWrapper.tsx diff --git a/android/src/main/java/com/reactnativeama/AmaPackage.kt b/android/src/main/java/com/reactnativeama/AmaPackage.kt index 61cdb8a9..d030eb9d 100644 --- a/android/src/main/java/com/reactnativeama/AmaPackage.kt +++ b/android/src/main/java/com/reactnativeama/AmaPackage.kt @@ -4,15 +4,10 @@ import com.facebook.react.ReactPackage import com.facebook.react.bridge.NativeModule import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.uimanager.ViewManager -import com.reactnativeama.components.AmaFlatListWrapperManager -import com.reactnativeama.modules.AMAAnimationsStatusModule +import com.reactnativeama.components.AMAWrapper class AmaPackage : ReactPackage { - override fun createNativeModules(reactContext: ReactApplicationContext): List { - return listOf(AMAAnimationsStatusModule(reactContext)) - } - override fun createViewManagers(reactContext: ReactApplicationContext): List> { - return listOf(AmaFlatListWrapperManager()) + return listOf(AMAWrapper()) } } diff --git a/android/src/main/java/com/reactnativeama/components/AMAWrapper.kt b/android/src/main/java/com/reactnativeama/components/AMAWrapper.kt new file mode 100644 index 00000000..65a11a20 --- /dev/null +++ b/android/src/main/java/com/reactnativeama/components/AMAWrapper.kt @@ -0,0 +1,13 @@ +package com.reactnativeama.components + +import android.content.Context +import android.view.ViewGroup +import android.view.accessibility.AccessibilityNodeInfo + +class AMAWrapper(context: Context?) : ViewGroup(context) { + private var rowsCount = 0 + private var columnsCount = 1 + + override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) { + } +} diff --git a/android/src/main/java/com/reactnativeama/components/AMAWrapperManager.kt b/android/src/main/java/com/reactnativeama/components/AMAWrapperManager.kt new file mode 100644 index 00000000..45b68a2a --- /dev/null +++ b/android/src/main/java/com/reactnativeama/components/AMAWrapperManager.kt @@ -0,0 +1,22 @@ +package com.reactnativeama.components + +import android.view.View +import com.facebook.react.uimanager.ViewGroupManager +import com.facebook.react.uimanager.ThemedReactContext +import com.facebook.react.uimanager.annotations.ReactProp + +class AMAWrapperManager : ViewGroupManager() { + private lateinit var container: AMAWrapper + + override fun getName() = "AMAWrapper" + + override fun createViewInstance(reactContext: ThemedReactContext): AMAWrapper { + container = AMAWrapper(reactContext) + + return container + } + + override fun addView(parent: AMAWrapper?, child: View?, index: Int) { + container.addView(child) + } +} diff --git a/android/src/main/java/com/reactnativeama/components/AmaFlatListWrapper.kt b/android/src/main/java/com/reactnativeama/components/AmaFlatListWrapper.kt deleted file mode 100644 index eea9a4bf..00000000 --- a/android/src/main/java/com/reactnativeama/components/AmaFlatListWrapper.kt +++ /dev/null @@ -1,42 +0,0 @@ -package com.reactnativeama.components - -import android.content.Context -import android.view.ViewGroup -import android.view.accessibility.AccessibilityNodeInfo - -class AmaFlatListWrapper(context: Context?) : ViewGroup(context) { - private var rowsCount = 0 - private var columnsCount = 1 - - init { - importantForAccessibility = IMPORTANT_FOR_ACCESSIBILITY_YES - focusable = FOCUSABLE - } - - override fun onInitializeAccessibilityNodeInfo(info: AccessibilityNodeInfo?) { - super.onInitializeAccessibilityNodeInfo(info) - - info?.collectionInfo = AccessibilityNodeInfo.CollectionInfo.obtain( - rowsCount, - columnsCount, - false - ) - } - - override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) { - } - - override fun setFocusable(focusable: Boolean) { - } - - override fun setFocusable(focusable: Int) { - } - - fun setRowsCount(count: Int) { - rowsCount = count - } - - fun setColumnsCount(count: Int) { - columnsCount = count - } -} diff --git a/android/src/main/java/com/reactnativeama/components/AmaFlatListWrapperManager.kt b/android/src/main/java/com/reactnativeama/components/AmaFlatListWrapperManager.kt deleted file mode 100644 index bdd5df08..00000000 --- a/android/src/main/java/com/reactnativeama/components/AmaFlatListWrapperManager.kt +++ /dev/null @@ -1,32 +0,0 @@ -package com.reactnativeama.components - -import android.view.View -import com.facebook.react.uimanager.ViewGroupManager -import com.facebook.react.uimanager.ThemedReactContext -import com.facebook.react.uimanager.annotations.ReactProp - -class AmaFlatListWrapperManager : ViewGroupManager() { - private lateinit var container: AmaFlatListWrapper - - override fun getName() = "AmaFlatListWrapper" - - override fun createViewInstance(reactContext: ThemedReactContext): AmaFlatListWrapper { - container = AmaFlatListWrapper(reactContext) - - return container - } - - @ReactProp(name = "rowsCount") - fun setRowsCount(view: AmaFlatListWrapper, count: Int) { - view.setRowsCount(count) - } - - @ReactProp(name = "columnsCount") - fun setColumnsCount(view: AmaFlatListWrapper, count: Int) { - view.setColumnsCount(count) - } - - override fun addView(parent: AmaFlatListWrapper?, child: View?, index: Int) { - container.addView(child) - } -} diff --git a/android/src/main/java/com/reactnativeama/modules/AMAAnimationsStatusModule.kt b/android/src/main/java/com/reactnativeama/modules/AMAAnimationsStatusModule.kt deleted file mode 100644 index 70ac614d..00000000 --- a/android/src/main/java/com/reactnativeama/modules/AMAAnimationsStatusModule.kt +++ /dev/null @@ -1,38 +0,0 @@ -package com.reactnativeama.modules - -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 android.provider.Settings -import androidx.annotation.NonNull - -class AMAAnimationsStatusModule(private val context: ReactApplicationContext) : - ReactContextBaseJavaModule(context) { - - @NonNull - override fun getName(): String { - return "AMAAnimationsStatus" - } - - @ReactMethod - fun areAnimationsEnabled(promise: Promise) { - val animationDurationScale = Settings.Global.getFloat( - context.getContentResolver(), - Settings.Global.ANIMATOR_DURATION_SCALE, - 1.0f - ) - val transitionAnimationScale = Settings.Global.getFloat( - context.getContentResolver(), - Settings.Global.TRANSITION_ANIMATION_SCALE, - 1.0f - ) - val windowAnimationScale = Settings.Global.getFloat( - context.getContentResolver(), - Settings.Global.WINDOW_ANIMATION_SCALE, - 1.0f - ) - - promise.resolve(animationDurationScale == 1f && transitionAnimationScale == 1f && windowAnimationScale == 1f) - } -} diff --git a/examples/bare/android/build.gradle b/examples/bare/android/build.gradle index 34ea7181..4a8b8a56 100644 --- a/examples/bare/android/build.gradle +++ b/examples/bare/android/build.gradle @@ -1,5 +1,3 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. - buildscript { ext { buildToolsVersion = "33.0.0" diff --git a/examples/expo/.gitignore b/examples/expo/.gitignore index 05647d55..a7b4abe8 100644 --- a/examples/expo/.gitignore +++ b/examples/expo/.gitignore @@ -33,3 +33,6 @@ yarn-error.* # typescript *.tsbuildinfo + +/android +/ios diff --git a/examples/expo/app.json b/examples/expo/app.json index f3a12fc3..7dbbd344 100644 --- a/examples/expo/app.json +++ b/examples/expo/app.json @@ -1,30 +1,33 @@ { - "expo": { - "name": "ama-expo-example", - "slug": "ama-expo-example", - "version": "1.0.0", - "orientation": "portrait", - "icon": "./assets/icon.png", - "userInterfaceStyle": "light", - "splash": { - "image": "./assets/splash.png", - "resizeMode": "contain", - "backgroundColor": "#ffffff" - }, - "assetBundlePatterns": [ - "**/*" - ], - "ios": { - "supportsTablet": true - }, - "android": { - "adaptiveIcon": { - "foregroundImage": "./assets/adaptive-icon.png", - "backgroundColor": "#ffffff" - } - }, - "web": { - "favicon": "./assets/favicon.png" + "expo": { + "name": "ama-expo-example", + "slug": "ama-expo-example", + "version": "1.0.0", + "orientation": "portrait", + "icon": "./assets/icon.png", + "userInterfaceStyle": "light", + "splash": { + "image": "./assets/splash.png", + "resizeMode": "contain", + "backgroundColor": "#ffffff" + }, + "assetBundlePatterns": [ + "**/*" + ], + "ios": { + "supportsTablet": true + }, + "android": { + "adaptiveIcon": { + "foregroundImage": "./assets/adaptive-icon.png", + "backgroundColor": "#ffffff" + }, + "icon": "./assets/icon.png", + "package": "com.nearform.reactnativeamaexpo", + "versionCode": 1 + }, + "web": { + "favicon": "./assets/favicon.png" + } } - } } diff --git a/examples/expo/package.json b/examples/expo/package.json index 81009947..85104491 100644 --- a/examples/expo/package.json +++ b/examples/expo/package.json @@ -4,15 +4,15 @@ "version": "1.0.0", "main": "index.js", "scripts": { - "start": "expo start", - "android": "expo start --android", - "ios": "expo start --ios", - "web": "expo start --web" + "start": "expo start --dev-client", + "android": "expo run:android", + "ios": "expo run:ios" }, "dependencies": { "@react-navigation/native": "^6.1.7", "@react-navigation/native-stack": "^6.9.14", "expo": "~49.0.10", + "expo-splash-screen": "~0.20.5", "expo-status-bar": "~1.6.0", "react": "18.2.0", "react-native": "0.72.4", diff --git a/packages/core/src/components/AMAProvider.tsx b/packages/core/src/components/AMAProvider.tsx index 6cfa48a7..aa95d7b9 100644 --- a/packages/core/src/components/AMAProvider.tsx +++ b/packages/core/src/components/AMAProvider.tsx @@ -6,10 +6,13 @@ import { AccessibilityChangeEventName, AccessibilityInfo, NativeEventSubscription, + Platform, Text, View, } from 'react-native'; +import { AMAWrapper } from './AMAWrapper'; + type AMAProviderProps = { children: React.ReactNode; }; @@ -170,21 +173,23 @@ export const AMAProvider: React.FC = ({ children }) => { }; return ( - - - <> - {children} - {failedItems.length > 0 ? ( - - ) : null} - - - + + + + <> + {children} + {failedItems.length > 0 ? ( + + ) : null} + + + + ); } diff --git a/packages/core/src/components/AMAWrapper.tsx b/packages/core/src/components/AMAWrapper.tsx new file mode 100644 index 00000000..49badebe --- /dev/null +++ b/packages/core/src/components/AMAWrapper.tsx @@ -0,0 +1,16 @@ +import * as React from 'react'; +import { Platform, requireNativeComponent } from 'react-native'; + +const isAndroid = Platform.OS === 'android'; + +type AMAWrapperProps = React.PropsWithChildren; + +const EmptyComponent: React.FC = ({ + children, +}: React.PropsWithChildren<{}>) => { + return <>{children}; +}; + +export const AMAWrapper = isAndroid + ? requireNativeComponent('AMAWrapper') + : EmptyComponent; diff --git a/packages/lists/src/components/ListWrapper.tsx b/packages/lists/src/components/ListWrapper.tsx index 6c951434..7d537568 100644 --- a/packages/lists/src/components/ListWrapper.tsx +++ b/packages/lists/src/components/ListWrapper.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import { Platform, requireNativeComponent } from 'react-native'; +import { Platform } from 'react-native'; type FlatListWrapperProps = React.PropsWithChildren<{ rowsCount: number; @@ -8,16 +8,8 @@ type FlatListWrapperProps = React.PropsWithChildren<{ const isAndroid = Platform.OS === 'android'; -export const ListWrapper = ({ - children, - rowsCount, - columnsCount = 1, -}: FlatListWrapperProps) => { - return ( - - {children} - - ); +export const ListWrapper = ({ children }: FlatListWrapperProps) => { + return {children}; }; /* @@ -30,6 +22,4 @@ const EmptyComponent: React.FC = ({ return <>{children}; }; -const AMAFlatListWrapper = isAndroid - ? requireNativeComponent('AmaFlatListWrapper') - : EmptyComponent; +const AMAFlatListWrapper = EmptyComponent; diff --git a/yarn.lock b/yarn.lock index 05e39393..78046a59 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2162,6 +2162,61 @@ mkdirp "^1.0.4" rimraf "^3.0.2" +"@react-native-ama/animations@*": + version "1.0.0" + resolved "https://registry.yarnpkg.com/@react-native-ama/animations/-/animations-1.0.0.tgz#d5497ddbf9592e02fed7620d710d9d681d076f2c" + integrity sha512-v2ikSd7gsZCc+s6ICo6y6AkprkMFFO+8Wy0wp97BlFFZzQOpJL37t4Iu4vg/qvLQqr/ickZt+MHwbuWeXp0siQ== + dependencies: + "@react-native-ama/core" "*" + "@react-native-ama/internal" "*" + +"@react-native-ama/core@*": + version "1.0.0" + resolved "https://registry.yarnpkg.com/@react-native-ama/core/-/core-1.0.0.tgz#213fea00bb55dcf627c3316a491cd1b6794a2443" + integrity sha512-9z7oD7inbqLAUH/5PTHVhcpnQ53DempL+F4AiGTmYiSi8rCkEDtmb1s6FB7LB8j0HitGFDedsBk16vWzhftviA== + dependencies: + "@react-native-ama/internal" "*" + +"@react-native-ama/extras@*": + version "1.0.0" + resolved "https://registry.yarnpkg.com/@react-native-ama/extras/-/extras-1.0.0.tgz#65a05e39f2665be3c94962523f8ab759e88321c3" + integrity sha512-00WHAnDKo+xtNJBK2wcRa6fGgFKmVeMLN9tyiPZ6h4Y1rYrJDsxIO+b0G2qpkcI6wdVS0oEUQB7+QrFwEkk/Cw== + dependencies: + "@react-native-ama/animations" "*" + "@react-native-ama/core" "*" + "@react-native-ama/internal" "*" + +"@react-native-ama/forms@*": + version "1.0.0" + resolved "https://registry.yarnpkg.com/@react-native-ama/forms/-/forms-1.0.0.tgz#b7911763bc15412eeea0f4f5c789948c8d4797ef" + integrity sha512-Ikbh/qJEH9hRrro2ytUvJkUE4pprPYgaTDXl/Ze0vPst/Hvo2fJAxV9j6cb4CuvTHMSZw3hdFyv3idqKRoLH1w== + dependencies: + "@react-native-ama/core" "*" + "@react-native-ama/internal" "*" + "@react-native-ama/react-native" "*" + +"@react-native-ama/internal@*": + version "0.0.1" + resolved "https://registry.yarnpkg.com/@react-native-ama/internal/-/internal-0.0.1.tgz#829c4812b2687df20533f5f91ecb9c134503eff2" + integrity sha512-60/EoLHIjMSf0U+wIv2cutPvG6Je/9hlAcmrvVSVfdMksAx0KAd2NagyCSvMAZ3AjB3GHSbUKJq8rmJ8t3Ew2g== + dependencies: + wcag-color "^1.1.1" + +"@react-native-ama/lists@*": + version "1.0.0" + resolved "https://registry.yarnpkg.com/@react-native-ama/lists/-/lists-1.0.0.tgz#697962f209555ff2fadd1ae26dbe1a5f5726af20" + integrity sha512-vEobld03sdrpzSTjYo4wNwhUIE9M5YZJJAoBdC8br7ybWuk9u5OntByF9doqqLCiMxQ5ZQoL5BCNOtb0FdDPlg== + dependencies: + "@react-native-ama/core" "*" + "@react-native-ama/internal" "*" + +"@react-native-ama/react-native@*": + version "1.0.0" + resolved "https://registry.yarnpkg.com/@react-native-ama/react-native/-/react-native-1.0.0.tgz#0810e3b44486649d7b1abe2cf9cdbd40c655400b" + integrity sha512-Ce+pAnjK0VgqnYmMGTLvyabH08aAPgGHsG/A5aqLrpa6kVEcjR1xj/dSpHTFDb5XC1aqNn/opCr3sG2u78iOAA== + dependencies: + "@react-native-ama/core" "*" + "@react-native-community/cli-clean@11.3.6": version "11.3.6" resolved "https://registry.yarnpkg.com/@react-native-community/cli-clean/-/cli-clean-11.3.6.tgz#43a06cbee1a5480da804debc4f94662a197720f2" @@ -4817,6 +4872,13 @@ expo-modules-core@1.5.11: compare-versions "^3.4.0" invariant "^2.2.4" +expo-splash-screen@~0.20.5: + version "0.20.5" + resolved "https://registry.yarnpkg.com/expo-splash-screen/-/expo-splash-screen-0.20.5.tgz#ebeba3e3977606830f74f506ab2cc25042bb7efd" + integrity sha512-nTALYdjHpeEA30rdOWSguxn72ctv8WM8ptuUgpfRgsWyn4i6rwYds/rBXisX69XO5fg+XjHAQqijGx/b28+3tg== + dependencies: + "@expo/prebuild-config" "6.2.6" + expo-status-bar@~1.6.0: version "1.6.0" resolved "https://registry.yarnpkg.com/expo-status-bar/-/expo-status-bar-1.6.0.tgz#e79ffdb9a84d2e0ec9a0dc7392d9ab364fefa9cf" From 9361d7a3cb32cc175779eaa703e4dd4d33956188 Mon Sep 17 00:00:00 2001 From: Alessandro Senese Date: Tue, 13 Aug 2024 13:56:06 +0100 Subject: [PATCH 2/6] app now builds from bare/android folder using gradlew --- examples/bare/android/app/build.gradle | 4 ++-- examples/bare/android/settings.gradle | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/bare/android/app/build.gradle b/examples/bare/android/app/build.gradle index 73311be3..47ef05b7 100644 --- a/examples/bare/android/app/build.gradle +++ b/examples/bare/android/app/build.gradle @@ -10,7 +10,7 @@ react { // The root of your project, i.e. where "package.json" lives. Default is '..' // root = file("../") // The folder where the react-native NPM package is. Default is ../node_modules/react-native - // reactNativeDir = file("../node_modules/react-native") + reactNativeDir = file("../../../../node_modules/react-native") // The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen // codegenDir = file("../node_modules/@react-native/codegen") // The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js @@ -120,4 +120,4 @@ dependencies { } } -apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) +apply from: file("../../../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) diff --git a/examples/bare/android/settings.gradle b/examples/bare/android/settings.gradle index 8d65ec2a..09b2fd38 100644 --- a/examples/bare/android/settings.gradle +++ b/examples/bare/android/settings.gradle @@ -1,4 +1,4 @@ rootProject.name = 'AMA Example' -apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) +apply from: file("../../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) include ':app' -includeBuild('../node_modules/@react-native/gradle-plugin') +includeBuild('../../../node_modules/@react-native/gradle-plugin') From a5a65e767dd4a3bab040e4cd89eb0061605e6351 Mon Sep 17 00:00:00 2001 From: Alessandro Senese Date: Wed, 14 Aug 2024 11:02:58 +0100 Subject: [PATCH 3/6] add "reactnativeama" dep to the bare project --- examples/bare/android/app/build.gradle | 4 ++++ examples/bare/android/settings.gradle | 3 +++ packages/core/src/components/AMAProvider.tsx | 1 - 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/bare/android/app/build.gradle b/examples/bare/android/app/build.gradle index 47ef05b7..ee8b4332 100644 --- a/examples/bare/android/app/build.gradle +++ b/examples/bare/android/app/build.gradle @@ -104,6 +104,8 @@ android { } dependencies { + implementation fileTree(dir: "libs", include: ["*.jar"]) + // The version of react-native is set by the React Native Gradle Plugin implementation("com.facebook.react:react-android") @@ -118,6 +120,8 @@ dependencies { } else { implementation jscFlavor } + + implementation project(':reactnativeama') } apply from: file("../../../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) diff --git a/examples/bare/android/settings.gradle b/examples/bare/android/settings.gradle index 09b2fd38..b2526298 100644 --- a/examples/bare/android/settings.gradle +++ b/examples/bare/android/settings.gradle @@ -2,3 +2,6 @@ rootProject.name = 'AMA Example' apply from: file("../../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) include ':app' includeBuild('../../../node_modules/@react-native/gradle-plugin') + +include ':reactnativeama' +project(':reactnativeama').projectDir = new File(rootProject.projectDir, '../../../android') diff --git a/packages/core/src/components/AMAProvider.tsx b/packages/core/src/components/AMAProvider.tsx index aa95d7b9..25245300 100644 --- a/packages/core/src/components/AMAProvider.tsx +++ b/packages/core/src/components/AMAProvider.tsx @@ -6,7 +6,6 @@ import { AccessibilityChangeEventName, AccessibilityInfo, NativeEventSubscription, - Platform, Text, View, } from 'react-native'; From a6870ea18e7fa5c0aee9d29387bedd708741cbd0 Mon Sep 17 00:00:00 2001 From: Alessandro Senese Date: Wed, 14 Aug 2024 11:07:43 +0100 Subject: [PATCH 4/6] specify kotlin_version to fix build issue --- examples/bare/android/build.gradle | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/examples/bare/android/build.gradle b/examples/bare/android/build.gradle index 4a8b8a56..e7b0703f 100644 --- a/examples/bare/android/build.gradle +++ b/examples/bare/android/build.gradle @@ -7,7 +7,15 @@ buildscript { // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP. ndkVersion = "23.1.7779620" + + // Set the kotlin version used in the Braze React SDK's buildscript + if (findProperty('android.kotlinVersion')) { + kotlin_version = findProperty('android.kotlinVersion') + } else { + kotlin_version = "1.8.10" + } } + repositories { google() mavenCentral() From 647b79e44415d77ac842b3902160a2d77d9cbb32 Mon Sep 17 00:00:00 2001 From: Alessandro Senese Date: Thu, 15 Aug 2024 11:54:32 +0100 Subject: [PATCH 5/6] add module --- .../java/com/reactnativeama/AmaPackage.kt | 16 ++++++++++-- .../modules/AMAKeyboardModule.kt | 25 +++++++++++++++++++ examples/bare/android/app/build.gradle | 3 ++- packages/core/src/components/AMAWrapper.tsx | 10 +++++--- 4 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 android/src/main/java/com/reactnativeama/modules/AMAKeyboardModule.kt diff --git a/android/src/main/java/com/reactnativeama/AmaPackage.kt b/android/src/main/java/com/reactnativeama/AmaPackage.kt index d030eb9d..11e15189 100644 --- a/android/src/main/java/com/reactnativeama/AmaPackage.kt +++ b/android/src/main/java/com/reactnativeama/AmaPackage.kt @@ -1,13 +1,25 @@ package com.reactnativeama +import android.util.Log import com.facebook.react.ReactPackage import com.facebook.react.bridge.NativeModule import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.uimanager.ViewManager -import com.reactnativeama.components.AMAWrapper +import com.reactnativeama.components.AMAWrapperManager +import com.reactnativeama.modules.AMAKeyboardModule class AmaPackage : ReactPackage { + init { + Log.d("AmaPackage", "AmaPackage is being initialized") + } + + override fun createNativeModules(reactContext: ReactApplicationContext): List { +throw IllegalArgumentException() + return listOf(AMAKeyboardModule(reactContext)) + } + override fun createViewManagers(reactContext: ReactApplicationContext): List> { - return listOf(AMAWrapper()) + Log.d("AmaPackage", "AmaPackage is being initialized") + return listOf(AMAWrapperManager()) } } diff --git a/android/src/main/java/com/reactnativeama/modules/AMAKeyboardModule.kt b/android/src/main/java/com/reactnativeama/modules/AMAKeyboardModule.kt new file mode 100644 index 00000000..eed964eb --- /dev/null +++ b/android/src/main/java/com/reactnativeama/modules/AMAKeyboardModule.kt @@ -0,0 +1,25 @@ +package com.reactnativeama.modules + +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 android.provider.Settings +import androidx.annotation.NonNull +import android.content.res.Configuration + +class AMAKeyboardModule(private val context: ReactApplicationContext) : + ReactContextBaseJavaModule(context) { + + @NonNull + override fun getName(): String { + return "AMAKeyboard" + } + + @ReactMethod + fun isKeyboardConnected(): Boolean { + val keyboard = context.resources.configuration.keyboard + + return keyboard != Configuration.KEYBOARD_UNDEFINED && keyboard != Configuration.KEYBOARD_NOKEYS + } +} diff --git a/examples/bare/android/app/build.gradle b/examples/bare/android/app/build.gradle index ee8b4332..c52d2507 100644 --- a/examples/bare/android/app/build.gradle +++ b/examples/bare/android/app/build.gradle @@ -124,4 +124,5 @@ dependencies { implementation project(':reactnativeama') } -apply from: file("../../../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) +apply from: file("../../../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); +applyNativeModulesAppBuildGradle(project) diff --git a/packages/core/src/components/AMAWrapper.tsx b/packages/core/src/components/AMAWrapper.tsx index 49badebe..bdcb635a 100644 --- a/packages/core/src/components/AMAWrapper.tsx +++ b/packages/core/src/components/AMAWrapper.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import { Platform, requireNativeComponent } from 'react-native'; +import { NativeModules, Platform, requireNativeComponent } from 'react-native'; const isAndroid = Platform.OS === 'android'; @@ -11,6 +11,8 @@ const EmptyComponent: React.FC = ({ return <>{children}; }; -export const AMAWrapper = isAndroid - ? requireNativeComponent('AMAWrapper') - : EmptyComponent; +console.info({ NativeModules }); +const a = requireNativeComponent('AMAWrapper'); + +console.info({ a }); +export const AMAWrapper = isAndroid ? a : EmptyComponent; From 485a7317b1a70a2d7cf5b4fded3576a64be274bd Mon Sep 17 00:00:00 2001 From: Alessandro Senese Date: Tue, 20 Aug 2024 11:38:29 +0200 Subject: [PATCH 6/6] updates --- examples/bare/android/build.gradle | 3 +++ examples/bare/android/settings.gradle | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/bare/android/build.gradle b/examples/bare/android/build.gradle index e7b0703f..b546a37e 100644 --- a/examples/bare/android/build.gradle +++ b/examples/bare/android/build.gradle @@ -23,5 +23,8 @@ buildscript { dependencies { classpath("com.android.tools.build:gradle") classpath("com.facebook.react:react-native-gradle-plugin") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin") } } + +apply plugin: "com.facebook.react.rootproject" diff --git a/examples/bare/android/settings.gradle b/examples/bare/android/settings.gradle index b2526298..97321b7c 100644 --- a/examples/bare/android/settings.gradle +++ b/examples/bare/android/settings.gradle @@ -1,7 +1,10 @@ +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 = 'AMA Example' -apply from: file("../../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) + include ':app' includeBuild('../../../node_modules/@react-native/gradle-plugin') include ':reactnativeama' -project(':reactnativeama').projectDir = new File(rootProject.projectDir, '../../../android') +project(':reactnativeama').projectDir = new File(rootProject.projectDir, '../../../../android')