react-native-orientation-director 2.3.1 → 2.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -50,7 +50,11 @@ You can install the package like any other Expo package, using the following com
|
|
|
50
50
|
npx expo install react-native-orientation-director
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
## Setup
|
|
54
|
+
|
|
55
|
+
### Expo
|
|
56
|
+
|
|
57
|
+
Simply add the library plugin to your `app.json` file:
|
|
54
58
|
|
|
55
59
|
```json
|
|
56
60
|
{
|
|
@@ -66,9 +70,9 @@ This way, Expo will handle the native setup for you during `prebuild`.
|
|
|
66
70
|
|
|
67
71
|
> Note: only SDK 50 and above are supported, the plugin is configured to handle only the kotlin template.
|
|
68
72
|
|
|
69
|
-
|
|
73
|
+
### Bare
|
|
70
74
|
|
|
71
|
-
|
|
75
|
+
#### Android
|
|
72
76
|
|
|
73
77
|
This library uses a custom broadcast receiver to handle the manual orientation changes: when the user disables the
|
|
74
78
|
autorotation feature and the system prompts the user to rotate the device, the library will listen to the broadcast
|
|
@@ -96,12 +100,12 @@ override fun onConfigurationChanged(newConfig: Configuration) {
|
|
|
96
100
|
|
|
97
101
|
Nothing else is required for Android.
|
|
98
102
|
|
|
99
|
-
|
|
103
|
+
#### iOS
|
|
100
104
|
|
|
101
105
|
To properly handle interface orientation changes in iOS, you need to update your AppDelegate file. Since React Native
|
|
102
106
|
0.77, the AppDelegate has been migrated to Swift, so see the instructions below for both Swift and Objective-C.
|
|
103
107
|
|
|
104
|
-
|
|
108
|
+
##### Objective-C
|
|
105
109
|
|
|
106
110
|
In your AppDelegate.h file, import "OrientationDirector.h" and implement supportedInterfaceOrientationsForWindow method as follows:
|
|
107
111
|
|
|
@@ -114,7 +118,7 @@ In your AppDelegate.h file, import "OrientationDirector.h" and implement support
|
|
|
114
118
|
}
|
|
115
119
|
```
|
|
116
120
|
|
|
117
|
-
|
|
121
|
+
##### Swift
|
|
118
122
|
|
|
119
123
|
You need to create a [bridging header](https://developer.apple.com/documentation/swift/importing-objective-c-into-swift#Import-Code-Within-an-App-Target)
|
|
120
124
|
to import the library, as shown below:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withRNOrientationMainActivity.d.ts","sourceRoot":"","sources":["../../../../plugin/src/withRNOrientationMainActivity.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EAGlB,MAAM,sBAAsB,CAAC;AAI9B,eAAO,MAAM,6BAA6B,EAAE,YAE3C,CAAC;AA0BF,wBAAgB,aAAa,CAAC,gBAAgB,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"withRNOrientationMainActivity.d.ts","sourceRoot":"","sources":["../../../../plugin/src/withRNOrientationMainActivity.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EAGlB,MAAM,sBAAsB,CAAC;AAI9B,eAAO,MAAM,6BAA6B,EAAE,YAE3C,CAAC;AA0BF,wBAAgB,aAAa,CAAC,gBAAgB,EAAE,MAAM,GAAG,MAAM,CA8C9D"}
|
package/package.json
CHANGED
|
@@ -23,11 +23,12 @@ function getCompatibleFileUpdater(language) {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
function ktFileUpdater(originalContents) {
|
|
26
|
-
const
|
|
26
|
+
const systemImportsContents = updateContentsWithSystemImports(originalContents);
|
|
27
|
+
const libraryImportCodeBlock = 'import com.orientationdirector.implementation.ConfigurationChangedBroadcastReceiver';
|
|
27
28
|
const rightBeforeClassDeclaration = /class MainActivity/g;
|
|
28
29
|
const importMergeResults = (0, generateCode_1.mergeContents)({
|
|
29
30
|
tag: '@react-native-orientation-director/library-import',
|
|
30
|
-
src:
|
|
31
|
+
src: systemImportsContents,
|
|
31
32
|
newSrc: libraryImportCodeBlock,
|
|
32
33
|
anchor: rightBeforeClassDeclaration,
|
|
33
34
|
offset: 0,
|
|
@@ -60,3 +61,40 @@ function ktFileUpdater(originalContents) {
|
|
|
60
61
|
});
|
|
61
62
|
return implementationMergeResults.contents;
|
|
62
63
|
}
|
|
64
|
+
function updateContentsWithSystemImports(originalContents) {
|
|
65
|
+
const rightBeforeClassDeclaration = /class MainActivity/g;
|
|
66
|
+
let possibleUpdatedContents = originalContents;
|
|
67
|
+
possibleUpdatedContents = addIntentImportIfNecessary(possibleUpdatedContents);
|
|
68
|
+
possibleUpdatedContents = addConfigurationImportIfNecessary(possibleUpdatedContents);
|
|
69
|
+
return possibleUpdatedContents;
|
|
70
|
+
function addIntentImportIfNecessary(_contents) {
|
|
71
|
+
const systemIntentImportCodeBlock = 'import android.content.Intent';
|
|
72
|
+
if (_contents.includes(systemIntentImportCodeBlock)) {
|
|
73
|
+
return _contents;
|
|
74
|
+
}
|
|
75
|
+
const mergeResults = (0, generateCode_1.mergeContents)({
|
|
76
|
+
tag: '@react-native-orientation-director/system-intent-import',
|
|
77
|
+
src: _contents,
|
|
78
|
+
newSrc: systemIntentImportCodeBlock,
|
|
79
|
+
anchor: rightBeforeClassDeclaration,
|
|
80
|
+
offset: 0,
|
|
81
|
+
comment: '// React Native Orientation Director',
|
|
82
|
+
});
|
|
83
|
+
return mergeResults.contents;
|
|
84
|
+
}
|
|
85
|
+
function addConfigurationImportIfNecessary(_contents) {
|
|
86
|
+
const systemConfigurationImportCodeBlock = 'import android.content.res.Configuration';
|
|
87
|
+
if (possibleUpdatedContents.includes(systemConfigurationImportCodeBlock)) {
|
|
88
|
+
return _contents;
|
|
89
|
+
}
|
|
90
|
+
const mergeResults = (0, generateCode_1.mergeContents)({
|
|
91
|
+
tag: '@react-native-orientation-director/system-configuration-import',
|
|
92
|
+
src: possibleUpdatedContents,
|
|
93
|
+
newSrc: systemConfigurationImportCodeBlock,
|
|
94
|
+
anchor: rightBeforeClassDeclaration,
|
|
95
|
+
offset: 0,
|
|
96
|
+
comment: '// React Native Orientation Director',
|
|
97
|
+
});
|
|
98
|
+
return mergeResults.contents;
|
|
99
|
+
}
|
|
100
|
+
}
|