Skip to content

Commit

Permalink
feat!: support RN 0.73
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
mateusz1913 committed Dec 19, 2023
1 parent 1dad449 commit aff4bba
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 113 deletions.
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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
84 changes: 17 additions & 67 deletions packages/react-native-avoid-softinput/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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')
Expand Down
20 changes: 6 additions & 14 deletions packages/react-native-avoid-softinput/android/spotless.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#import <React/RCTRootView.h>
#import <React/RCTUtils.h>
#ifdef RCT_NEW_ARCH_ENABLED
#import <React/RCTFabricSurfaceHostingProxyRootView.h>
#import <React/RCTSurfaceHostingProxyRootView.h>
#endif

@implementation AvoidSoftInputObjCPPUtils
Expand All @@ -28,7 +28,7 @@ + (UIView *_Nullable)getReactRootView
if ([
presentedViewController.view isKindOfClass:[
#ifdef RCT_NEW_ARCH_ENABLED
RCTFabricSurfaceHostingProxyRootView
RCTSurfaceHostingProxyRootView
#else
RCTRootView
#endif
Expand Down
6 changes: 3 additions & 3 deletions packages/react-native-avoid-softinput/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
12 changes: 8 additions & 4 deletions packages/react-native-avoid-softinput/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export interface SoftInputAppliedOffsetEventData {
appliedOffset: number;
}

export type SoftInputEvent = NativeSyntheticEvent<SoftInputEventData>;

export type SoftInputAppliedOffsetEvent = NativeSyntheticEvent<SoftInputAppliedOffsetEventData>;

export type SoftInputEasing = 'easeIn' | 'easeInOut' | 'easeOut' | 'linear';

export interface AvoidSoftInputNativeModuleType {
Expand Down Expand Up @@ -57,8 +61,8 @@ export interface AvoidSoftInputViewProps extends Omit<ViewProps, 'pointerEvents'
* @default 660 ms
*/
showAnimationDuration?: number;
onSoftInputAppliedOffsetChange?: (e: NativeSyntheticEvent<SoftInputAppliedOffsetEventData>) => void;
onSoftInputHeightChange?: (e: NativeSyntheticEvent<SoftInputEventData>) => void;
onSoftInputHidden?: (e: NativeSyntheticEvent<SoftInputEventData>) => void;
onSoftInputShown?: (e: NativeSyntheticEvent<SoftInputEventData>) => void;
onSoftInputAppliedOffsetChange?: (e: SoftInputAppliedOffsetEvent) => void;
onSoftInputHeightChange?: (e: SoftInputEvent) => void;
onSoftInputHidden?: (e: SoftInputEvent) => void;
onSoftInputShown?: (e: SoftInputEvent) => void;
}

0 comments on commit aff4bba

Please sign in to comment.