Skip to content

Commit 32e6a84

Browse files
authored
feat: drop old arch support (#102)
1 parent 073e134 commit 32e6a84

49 files changed

Lines changed: 1206 additions & 1827 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/pr.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,6 @@ jobs:
100100
restore-keys: |
101101
${{ runner.os }}-gradle-
102102
103-
- name: Run test
104-
if: env.turbo_cache_hit != 1
105-
run: |
106-
cd example/android && ./gradlew react-native-orientation-director:testDebugUnitTest
107-
108103
- name: Build example for Android
109104
env:
110105
JAVA_OPTS: "-XX:MaxHeapSize=6g"

.github/workflows/release.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,6 @@ jobs:
134134
restore-keys: |
135135
${{ runner.os }}-gradle-
136136
137-
- name: Run test
138-
if: env.turbo_cache_hit != 1
139-
run: |
140-
cd example/android && ./gradlew react-native-orientation-director:testDebugUnitTest
141-
142137
- name: Build example for Android
143138
env:
144139
JAVA_OPTS: "-XX:MaxHeapSize=6g"

README.md

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77
A React Native library that allows you to listen to orientation changes, lock interface orientation
88
to a selected one and get current orientation.
9-
Written in Kotlin, Swift and Typescript. It supports both the Old and New React Native architecture.
9+
Written in Kotlin, Swift and Typescript.
10+
11+
Kindly note that this library only supports the new architecture since v3.0.0, if you are looking for a version that
12+
supports the old architecture, please check older versions.
1013

1114
This library takes inspiration from and builds upon the following amazing alternatives:
1215

@@ -112,40 +115,20 @@ Nothing else is required for Android.
112115

113116
#### iOS
114117

115-
To properly handle interface orientation changes in iOS, you need to update your AppDelegate file. Since React Native
116-
0.77, the AppDelegate has been migrated to Swift, so see the instructions below for both Swift and Objective-C.
118+
To properly handle interface orientation changes in iOS, you need to update your AppDelegate file. Follow the instructions
119+
below to set it up:
117120

118-
##### Objective-C
121+
In your AppDelegate.swift file, implement the supportedInterfaceOrientationsFor method as follows:
119122

120-
In your AppDelegate.mm file, import "OrientationDirector.h" and implement supportedInterfaceOrientationsForWindow method as follows:
123+
```swift
121124

122-
```objc
123-
#import <OrientationDirector.h>
125+
import OrientationDirector
124126

125-
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
126-
{
127-
return [OrientationDirector getSupportedInterfaceOrientationsForWindow];
127+
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
128+
return SharedOrientationDirectorImpl.shared.supportedInterfaceOrientations
128129
}
129-
```
130-
131-
##### Swift
132-
133-
You need to create a [bridging header](https://developer.apple.com/documentation/swift/importing-objective-c-into-swift#Import-Code-Within-an-App-Target)
134-
to import the library, as shown below:
135130

136131
```
137-
#import "OrientationDirector.h"
138-
```
139-
140-
Then, in your AppDelegate.swift file, implement the supportedInterfaceOrientationsFor method as follows:
141-
142-
```swift
143-
override func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
144-
return OrientationDirector.getSupportedInterfaceOrientationsForWindow()
145-
}
146-
```
147-
148-
Note: if you are targeting react-native > 79.x, you can omit the `override` keyword.
149132

150133
If you need help, you can check the example project.
151134

@@ -212,11 +195,6 @@ differently than on iOS, mainly in the following ways:
212195

213196
This behavior allows us to follow Google's best practices related to the Sensors Framework. More [here](https://developer.android.com/develop/sensors-and-location/sensors/sensors_overview#sensors-practices).
214197

215-
## Roadmap
216-
217-
- [ ] Add JS side tests
218-
- [ ] Add iOS side tests
219-
220198
## Contributing
221199

222200
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.

android/build.gradle

Lines changed: 19 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
buildscript {
2-
ext.getExtOrDefault = {name ->
3-
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['OrientationDirector_' + name]
2+
ext.OrientationDirector = [
3+
kotlinVersion: "2.0.21",
4+
minSdkVersion: 24,
5+
compileSdkVersion: 36,
6+
targetSdkVersion: 36
7+
]
8+
9+
ext.getExtOrDefault = { prop ->
10+
if (rootProject.ext.has(prop)) {
11+
return rootProject.ext.get(prop)
12+
}
13+
14+
return OrientationDirector[prop]
415
}
516

617
repositories {
@@ -16,51 +27,19 @@ buildscript {
1627
}
1728

1829

19-
def isNewArchitectureEnabled() {
20-
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
21-
}
22-
2330
apply plugin: "com.android.library"
2431
apply plugin: "kotlin-android"
2532

26-
if (isNewArchitectureEnabled()) {
27-
apply plugin: "com.facebook.react"
28-
}
29-
30-
def getExtOrIntegerDefault(name) {
31-
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["OrientationDirector_" + name]).toInteger()
32-
}
33-
34-
def getDefault(name) {
35-
return project.properties["OrientationDirector_" + name]
36-
}
37-
38-
def supportsNamespace() {
39-
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
40-
def major = parsed[0].toInteger()
41-
def minor = parsed[1].toInteger()
42-
43-
// Namespace support was added in 7.3.0
44-
return (major == 7 && minor >= 3) || major >= 8
45-
}
33+
apply plugin: "com.facebook.react"
4634

4735
android {
48-
if (supportsNamespace()) {
49-
namespace "com.orientationdirector"
36+
namespace "com.orientationdirector"
5037

51-
sourceSets {
52-
main {
53-
manifest.srcFile "src/main/AndroidManifestNew.xml"
54-
}
55-
}
56-
}
57-
58-
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
38+
compileSdkVersion getExtOrDefault("compileSdkVersion")
5939

6040
defaultConfig {
61-
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
62-
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
63-
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
41+
minSdkVersion getExtOrDefault("minSdkVersion")
42+
targetSdkVersion getExtOrDefault("targetSdkVersion")
6443
}
6544

6645
buildFeatures {
@@ -73,55 +52,16 @@ android {
7352
}
7453
}
7554

76-
lintOptions {
55+
lint {
7756
disable "GradleCompatible"
7857
}
7958

8059
compileOptions {
8160
sourceCompatibility JavaVersion.VERSION_1_8
8261
targetCompatibility JavaVersion.VERSION_1_8
8362
}
84-
85-
sourceSets {
86-
main {
87-
if (isNewArchitectureEnabled()) {
88-
java.srcDirs += [
89-
"src/newarch",
90-
// This is needed to build Kotlin project with NewArch enabled
91-
"${project.buildDir}/generated/source/codegen/java"
92-
]
93-
} else {
94-
java.srcDirs += ["src/oldarch"]
95-
}
96-
}
97-
}
98-
}
99-
100-
repositories {
101-
mavenCentral()
102-
google()
10363
}
10464

105-
def kotlin_version = getExtOrDefault("kotlinVersion")
106-
def junit_version = getDefault("junitVersion")
107-
def android_x_core_version = getDefault("androidXCoreVersion")
108-
def robolectric_version = getDefault("robolectricVersion")
109-
def mockito_core_version = getDefault("mockitoCoreVersion")
110-
11165
dependencies {
11266
implementation "com.facebook.react:react-android"
113-
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
114-
115-
testImplementation "junit:junit:$junit_version"
116-
testImplementation "androidx.test:core:$android_x_core_version"
117-
testImplementation "org.robolectric:robolectric:$robolectric_version"
118-
testImplementation "org.mockito:mockito-core:$mockito_core_version"
119-
}
120-
121-
if (isNewArchitectureEnabled()) {
122-
react {
123-
jsRootDir = file("../src/")
124-
libraryName = "OrientationDirector"
125-
codegenJavaPackageName = "com.orientationdirector"
126-
}
12767
}

android/gradle.properties

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.orientationdirector">
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
32
</manifest>

android/src/main/AndroidManifestNew.xml

Lines changed: 0 additions & 2 deletions
This file was deleted.

android/src/newarch/OrientationDirectorModule.kt renamed to android/src/main/java/com/orientationdirector/OrientationDirectorModule.kt

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,33 @@ package com.orientationdirector
22

33
import com.facebook.react.bridge.Promise
44
import com.facebook.react.bridge.ReactApplicationContext
5+
import com.facebook.react.bridge.WritableMap
6+
import com.orientationdirector.implementation.EventManagerDelegate
57
import com.orientationdirector.implementation.OrientationDirectorModuleImpl
68

7-
class OrientationDirectorModule internal constructor(context: ReactApplicationContext) :
8-
NativeOrientationDirectorSpec(context) {
9+
class OrientationDirectorModule(reactContext: ReactApplicationContext) :
10+
NativeOrientationDirectorSpec(reactContext), EventManagerDelegate {
911

10-
private var implementation = OrientationDirectorModuleImpl(context)
11-
12-
override fun getName() = OrientationDirectorModuleImpl.NAME
12+
override fun getName() = NAME
1313

14+
private var implementation = OrientationDirectorModuleImpl(reactContext, this)
1415

1516
override fun getInterfaceOrientation(promise: Promise) {
1617
promise.resolve(implementation.getInterfaceOrientation().ordinal)
1718
}
1819

19-
2020
override fun getDeviceOrientation(promise: Promise) {
2121
promise.resolve(implementation.getDeviceOrientation().ordinal)
2222
}
2323

24-
2524
override fun lockTo(orientation: Double) {
2625
implementation.lockTo(orientation.toInt())
2726
}
2827

29-
3028
override fun unlock() {
3129
implementation.unlock()
3230
}
3331

34-
3532
override fun resetSupportedInterfaceOrientations() {
3633
implementation.resetSupportedInterfaceOrientations()
3734
}
@@ -52,8 +49,20 @@ class OrientationDirectorModule internal constructor(context: ReactApplicationCo
5249
return implementation.disableOrientationSensors()
5350
}
5451

55-
override fun addListener(eventName: String) {}
52+
override fun sendOnDeviceOrientationChanged(params: WritableMap) {
53+
emitOnDeviceOrientationChanged(params)
54+
}
5655

57-
override fun removeListeners(count: Double) {}
56+
override fun sendOnInterfaceOrientationChanged(params: WritableMap) {
57+
emitOnInterfaceOrientationChanged(params)
58+
}
59+
60+
override fun sendOnLockChanged(params: WritableMap) {
61+
emitOnLockChanged(params)
62+
}
63+
64+
companion object {
65+
const val NAME = OrientationDirectorModuleImpl.NAME
66+
}
5867

5968
}
Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,30 @@
11
package com.orientationdirector
22

33
import com.facebook.react.BaseReactPackage
4-
import com.facebook.react.bridge.ReactApplicationContext
54
import com.facebook.react.bridge.NativeModule
6-
import com.facebook.react.module.model.ReactModuleInfoProvider
5+
import com.facebook.react.bridge.ReactApplicationContext
76
import com.facebook.react.module.model.ReactModuleInfo
8-
import com.orientationdirector.implementation.OrientationDirectorModuleImpl
9-
import java.util.HashMap
7+
import com.facebook.react.module.model.ReactModuleInfoProvider
108

119
class OrientationDirectorPackage : BaseReactPackage() {
12-
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
13-
return if (name == OrientationDirectorModuleImpl.NAME) {
10+
11+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? =
12+
if (name == OrientationDirectorModule.NAME) {
1413
OrientationDirectorModule(reactContext)
1514
} else {
1615
null
1716
}
18-
}
1917

20-
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
21-
return ReactModuleInfoProvider {
22-
val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
23-
val isTurboModule: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
24-
moduleInfos[OrientationDirectorModuleImpl.NAME] = ReactModuleInfo(
25-
OrientationDirectorModuleImpl.NAME,
26-
OrientationDirectorModuleImpl.NAME,
27-
false, // canOverrideExistingModule
28-
false, // needsEagerInit
29-
false, // isCxxModule
30-
isTurboModule // isTurboModule
18+
override fun getReactModuleInfoProvider() = ReactModuleInfoProvider {
19+
mapOf(
20+
OrientationDirectorModule.NAME to ReactModuleInfo(
21+
name = OrientationDirectorModule.NAME,
22+
className = OrientationDirectorModule.NAME,
23+
canOverrideExistingModule = false,
24+
needsEagerInit = false,
25+
isCxxModule = false,
26+
isTurboModule = true
3127
)
32-
moduleInfos
33-
}
28+
)
3429
}
3530
}

0 commit comments

Comments
 (0)