From dd058da32956d97cb043041e3ac695a2468e6bc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20M=C4=99drek?= Date: Tue, 19 Dec 2023 16:26:34 +0100 Subject: [PATCH] feat!: support RN 0.73 Support RN version 0.73, according to the policy of supporting latest and two previous minor releases it means dropping support for RN version 0.70 (adjusted library's package.json peerDeps) --- CONTRIBUTING.md | 6 +- .../ReactNativeAvoidSoftinput.podspec | 24 +----- .../android/build.gradle | 84 ++++--------------- .../android/spotless.gradle | 20 ++--- .../android/src/main/AndroidManifestNew.xml | 3 + .../ios/AvoidSoftInputObjCPPUtils.mm | 4 +- .../react-native-avoid-softinput/package.json | 6 +- .../react-native-avoid-softinput/src/types.ts | 12 ++- 8 files changed, 46 insertions(+), 113 deletions(-) create mode 100644 packages/react-native-avoid-softinput/android/src/main/AndroidManifestNew.xml diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9b565ac..bde4286 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -104,7 +104,7 @@ git branch chore/2-configuration - [ESLint](https://eslint.org/) - JS/TS linting - [dprint](https://dprint.dev/) - JS/TS formatting - [TypeScript](https://www.typescriptlang.org/) - TS type checking -- [Spotless](https://github.com/diffplug/spotless) & [Ktlint](https://github.com/pinterest/ktlint) - Kotlin/Java linting and formatting +- [Spotless](https://github.com/diffplug/spotless) & [Ktfmt](https://github.com/facebook/ktfmt) - Kotlin/Java linting and formatting - [SwiftFormat](https://github.com/nicklockwood/SwiftFormat) - Swift formatting - [SwiftLint](https://github.com/realm/SwiftLint) - Swift linting - [ClangFormat](https://clang.llvm.org/) - ObjC/ObjC++ linting and formatting @@ -127,13 +127,13 @@ The `package.json` file contains various scripts for common tasks: - `yarn typescript`: type-check files with TypeScript. - `yarn lint:js`: lint all JS/TS files with ESLint. -- `yarn lint:android`: run linter (Spotless/Ktlint) for all Kotlin/Java files. +- `yarn lint:android`: run linter (Spotless/Ktfmt) for all Kotlin/Java files. - `yarn lint:ios:swift`: run linter (SwiftLint) for all Swift files within old arch project (install [SwiftLint](https://github.com/realm/SwiftLint) e.g. with Homebrew). - `yarn lint:ios:objc`: run linter (ClangFormat) for all ObjC/ObjC++ files within old arch project (install [ClangFormat](https://clang.llvm.org/) e.g. with Homebrew). - `yarn lint:fabric:ios:swift`: run linter (SwiftLint) for all Swift files within new arch project (install [SwiftLint](https://github.com/realm/SwiftLint) e.g. with Homebrew). - `yarn lint:fabric:ios:objc`: run linter (ClangFormat) for all ObjC/ObjC++ files within new arch project (install [ClangFormat](https://clang.llvm.org/) e.g. with Homebrew). - `yarn format:js`: format all JS/TS files with dprint. -- `yarn format:android`: format (Spotless/Ktlint) all Kotlin/Java files. +- `yarn format:android`: format (Spotless/Ktfmt) all Kotlin/Java files. - `yarn format:ios:swift`: format (SwiftFormat) all Swift files within old arch project (install [SwiftFormat](https://github.com/nicklockwood/SwiftFormat) e.g. with Homebrew). - `yarn format:ios:objc`: format (ClangFormat) all ObjC/ObjC++ files within old arch project (install [ClangFormat](https://clang.llvm.org/) e.g. with Homebrew). - `yarn format:fabric:ios:swift`: format (SwiftFormat) all Swift files within new arch project (install [SwiftFormat](https://github.com/nicklockwood/SwiftFormat) e.g. with Homebrew). diff --git a/packages/react-native-avoid-softinput/ReactNativeAvoidSoftinput.podspec b/packages/react-native-avoid-softinput/ReactNativeAvoidSoftinput.podspec index 7cd1ab7..2ca3dad 100644 --- a/packages/react-native-avoid-softinput/ReactNativeAvoidSoftinput.podspec +++ b/packages/react-native-avoid-softinput/ReactNativeAvoidSoftinput.podspec @@ -2,13 +2,7 @@ require "json" package = JSON.parse(File.read(File.join(__dir__, "package.json"))) -# TODO -# Migrate to install_module_dependencies https://github.com/facebook/react-native/commit/82e9c6ad611f1fb816de056ff031716f8cb24b4e#diff-adcf572f001c2b710d14f409c14763f1a50b08369b3034548f1602685d21f67f -# when library will drop support for RN < 0.71 - -fabric_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == '1' - -folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32' +new_arch_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == '1' Pod::Spec.new do |s| s.name = "ReactNativeAvoidSoftinput" @@ -22,14 +16,9 @@ Pod::Spec.new do |s| s.source = { :git => "https://github.com/mateusz1913/react-native-avoid-softinput.git", :tag => "#{s.version}" } s.source_files = "ios/**/*.{h,m,mm,cpp,swift}" - s.dependency "React-Core" - if fabric_enabled - s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1" + if new_arch_enabled s.pod_target_xcconfig = { - "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"", - "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1", - "CLANG_CXX_LANGUAGE_STANDARD" => "c++17", "DEFINES_MODULE" => "YES", "SWIFT_OBJC_INTERFACE_HEADER_NAME" => "ReactNativeAvoidSoftinput-Swift.h", # This is handy when we want to detect if new arch is enabled in Swift code @@ -41,17 +30,12 @@ Pod::Spec.new do |s| # #endif "OTHER_SWIFT_FLAGS" => "-DAVOID_SOFTINPUT_NEW_ARCH_ENABLED" } - - s.dependency "React-RCTFabric" - s.dependency "React-Codegen" - s.dependency "RCT-Folly" - s.dependency "RCTRequired" - s.dependency "RCTTypeSafety" - s.dependency "ReactCommon/turbomodule/core" else s.pod_target_xcconfig = { "DEFINES_MODULE" => "YES", "SWIFT_OBJC_INTERFACE_HEADER_NAME" => "ReactNativeAvoidSoftinput-Swift.h" } end + + install_modules_dependencies(s) end diff --git a/packages/react-native-avoid-softinput/android/build.gradle b/packages/react-native-avoid-softinput/android/build.gradle index 9436b87..09d2163 100644 --- a/packages/react-native-avoid-softinput/android/build.gradle +++ b/packages/react-native-avoid-softinput/android/build.gradle @@ -11,7 +11,7 @@ buildscript { classpath("com.android.tools.build:gradle:8.0.2") // noinspection DifferentKotlinGradleVersion classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath "com.diffplug.spotless:spotless-plugin-gradle:6.13.0" + classpath "com.diffplug.spotless:spotless-plugin-gradle:6.22.0" } } @@ -53,11 +53,26 @@ def reactNativeArchitectures() { return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"] } +def supportsNamespace() { + def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.') + def major = parsed[0].toInteger() + def minor = parsed[1].toInteger() + + // Namespace support was added in 7.3.0 + return (major == 7 && minor >= 3) || major >= 8 +} + android { compileSdkVersion getExtOrIntegerDefault('compileSdkVersion') - if (project.android.hasProperty("namespace")) { + if (supportsNamespace()) { namespace "com.reactnativeavoidsoftinput" + + sourceSets { + main { + manifest.srcFile "src/main/AndroidManifestNew.xml" + } + } } buildFeatures { @@ -101,71 +116,6 @@ android { repositories { mavenCentral() google() - - def found = false - def defaultDir = null - def androidSourcesName = 'React Native sources' - - if (rootProject.ext.has('reactNativeAndroidRoot')) { - defaultDir = rootProject.ext.get('reactNativeAndroidRoot') - } else { - defaultDir = new File( - projectDir, - '/../../../node_modules/react-native/android' - ) - } - - if (defaultDir.exists()) { - maven { - url defaultDir.toString() - name androidSourcesName - } - - logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}") - found = true - } else { - def parentDir = rootProject.projectDir - - 1.upto(5, { - if (found) return true - parentDir = parentDir.parentFile - - def androidSourcesDir = new File( - parentDir, - 'node_modules/react-native' - ) - - def androidPrebuiltBinaryDir = new File( - parentDir, - 'node_modules/react-native/android' - ) - - if (androidPrebuiltBinaryDir.exists()) { - maven { - url androidPrebuiltBinaryDir.toString() - name androidSourcesName - } - - logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}") - found = true - } else if (androidSourcesDir.exists()) { - maven { - url androidSourcesDir.toString() - name androidSourcesName - } - - logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}") - found = true - } - }) - } - - if (!found) { - throw new GradleException( - "${project.name}: unable to locate React Native android sources. " + - "Ensure you have you installed React Native as a dependency in your project and try again." - ) - } } def kotlin_version = getExtOrDefault('kotlinVersion') diff --git a/packages/react-native-avoid-softinput/android/spotless.gradle b/packages/react-native-avoid-softinput/android/spotless.gradle index d4eff3e..0e94899 100644 --- a/packages/react-native-avoid-softinput/android/spotless.gradle +++ b/packages/react-native-avoid-softinput/android/spotless.gradle @@ -2,21 +2,13 @@ apply plugin: 'com.diffplug.spotless' spotless { - java { - target 'src/*/java/**/*.java' - googleJavaFormat() - } kotlin { target 'src/**/*.kt' - /** - * if some rule has to be disabled: - * ktlint() - * .userData(["disabled_rules": "no-wildcard-imports"]) - */ - ktlint("0.47.1") - .editorConfigOverride(["indent_size": 2]) - trimTrailingWhitespace() - indentWithSpaces() - endWithNewline() + targetExclude "$buildDir/**/*.kt" + ktfmt().kotlinlangStyle() + } + kotlinGradle { + target '*.gradle.kts' + ktfmt().kotlinlangStyle() } } diff --git a/packages/react-native-avoid-softinput/android/src/main/AndroidManifestNew.xml b/packages/react-native-avoid-softinput/android/src/main/AndroidManifestNew.xml new file mode 100644 index 0000000..0a0938a --- /dev/null +++ b/packages/react-native-avoid-softinput/android/src/main/AndroidManifestNew.xml @@ -0,0 +1,3 @@ + + + diff --git a/packages/react-native-avoid-softinput/ios/AvoidSoftInputObjCPPUtils.mm b/packages/react-native-avoid-softinput/ios/AvoidSoftInputObjCPPUtils.mm index 2a37cb5..6a389a3 100644 --- a/packages/react-native-avoid-softinput/ios/AvoidSoftInputObjCPPUtils.mm +++ b/packages/react-native-avoid-softinput/ios/AvoidSoftInputObjCPPUtils.mm @@ -3,7 +3,7 @@ #import #import #ifdef RCT_NEW_ARCH_ENABLED -#import +#import #endif @implementation AvoidSoftInputObjCPPUtils @@ -28,7 +28,7 @@ + (UIView *_Nullable)getReactRootView if ([ presentedViewController.view isKindOfClass:[ #ifdef RCT_NEW_ARCH_ENABLED - RCTFabricSurfaceHostingProxyRootView + RCTSurfaceHostingProxyRootView #else RCTRootView #endif diff --git a/packages/react-native-avoid-softinput/package.json b/packages/react-native-avoid-softinput/package.json index fefbd62..b42e14d 100644 --- a/packages/react-native-avoid-softinput/package.json +++ b/packages/react-native-avoid-softinput/package.json @@ -57,15 +57,15 @@ }, "devDependencies": { "@release-it/conventional-changelog": "6.0.0", - "@types/react": "18.2.14", + "@types/react": "18.2.42", "react": "18.2.0", - "react-native": "0.72.1", + "react-native": "patch:react-native@npm%3A0.73.1#~/.yarn/patches/react-native-npm-0.73.1-35751404af.patch", "react-native-builder-bob": "0.21.2", "release-it": "16.0.0" }, "peerDependencies": { "react": ">=17.0.0", - "react-native": ">=0.65.0" + "react-native": ">=0.71.0" }, "release-it": { "git": { diff --git a/packages/react-native-avoid-softinput/src/types.ts b/packages/react-native-avoid-softinput/src/types.ts index 7f26dbb..1a667f0 100644 --- a/packages/react-native-avoid-softinput/src/types.ts +++ b/packages/react-native-avoid-softinput/src/types.ts @@ -8,6 +8,10 @@ export interface SoftInputAppliedOffsetEventData { appliedOffset: number; } +export type SoftInputEvent = NativeSyntheticEvent; + +export type SoftInputAppliedOffsetEvent = NativeSyntheticEvent; + export type SoftInputEasing = 'easeIn' | 'easeInOut' | 'easeOut' | 'linear'; export interface AvoidSoftInputNativeModuleType { @@ -57,8 +61,8 @@ export interface AvoidSoftInputViewProps extends Omit) => void; - onSoftInputHeightChange?: (e: NativeSyntheticEvent) => void; - onSoftInputHidden?: (e: NativeSyntheticEvent) => void; - onSoftInputShown?: (e: NativeSyntheticEvent) => void; + onSoftInputAppliedOffsetChange?: (e: SoftInputAppliedOffsetEvent) => void; + onSoftInputHeightChange?: (e: SoftInputEvent) => void; + onSoftInputHidden?: (e: SoftInputEvent) => void; + onSoftInputShown?: (e: SoftInputEvent) => void; }