expo-rotation-module 0.1.0
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/.eslintrc.js +5 -0
- package/README.md +77 -0
- package/android/.gradle/8.14.3/checksums/checksums.lock +0 -0
- package/android/.gradle/8.14.3/fileChanges/last-build.bin +0 -0
- package/android/.gradle/8.14.3/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/8.14.3/gc.properties +0 -0
- package/android/.gradle/9.0-milestone-1/checksums/checksums.lock +0 -0
- package/android/.gradle/9.0-milestone-1/fileChanges/last-build.bin +0 -0
- package/android/.gradle/9.0-milestone-1/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/9.0-milestone-1/gc.properties +0 -0
- package/android/.gradle/9.2.0/checksums/checksums.lock +0 -0
- package/android/.gradle/9.2.0/fileChanges/last-build.bin +0 -0
- package/android/.gradle/9.2.0/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/9.2.0/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
- package/android/.gradle/config.properties +2 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/.idea/AndroidProjectSystem.xml +6 -0
- package/android/.idea/caches/deviceStreaming.xml +1210 -0
- package/android/.idea/gradle.xml +12 -0
- package/android/.idea/migrations.xml +10 -0
- package/android/.idea/misc.xml +10 -0
- package/android/.idea/runConfigurations.xml +17 -0
- package/android/.idea/vcs.xml +6 -0
- package/android/.idea/workspace.xml +63 -0
- package/android/build.gradle +43 -0
- package/android/kls_database.db +0 -0
- package/android/local.properties +8 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/ktsierra/expo/rotationmodule/ExpoRotationModule.kt +131 -0
- package/app.plugin.js +3 -0
- package/build/ExpoRotationModule.d.ts +15 -0
- package/build/ExpoRotationModule.d.ts.map +1 -0
- package/build/ExpoRotationModule.js +76 -0
- package/build/ExpoRotationModule.js.map +1 -0
- package/build/ExpoRotationModule.types.d.ts +18 -0
- package/build/ExpoRotationModule.types.d.ts.map +1 -0
- package/build/ExpoRotationModule.types.js +2 -0
- package/build/ExpoRotationModule.types.js.map +1 -0
- package/build/ExpoRotationModule.web.d.ts +12 -0
- package/build/ExpoRotationModule.web.d.ts.map +1 -0
- package/build/ExpoRotationModule.web.js +17 -0
- package/build/ExpoRotationModule.web.js.map +1 -0
- package/build/index.d.ts +3 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +3 -0
- package/build/index.js.map +1 -0
- package/expo-module.config.json +9 -0
- package/index.js +2 -0
- package/ios/ExpoRotationModule.podspec +29 -0
- package/ios/ExpoRotationModule.swift +48 -0
- package/package.json +48 -0
- package/plugin/index.js +33 -0
- package/src/ExpoRotationModule.ts +86 -0
- package/src/ExpoRotationModule.types.ts +19 -0
- package/src/ExpoRotationModule.web.ts +21 -0
- package/src/index.d.ts +17 -0
- package/src/index.ts +2 -0
- package/tsconfig.json +9 -0
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "expo-rotation-module",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Screen Orientation Native Module",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "src/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "expo-module build",
|
|
9
|
+
"clean": "expo-module clean",
|
|
10
|
+
"lint": "expo-module lint",
|
|
11
|
+
"test": "expo-module test",
|
|
12
|
+
"prepare": "expo-module prepare",
|
|
13
|
+
"prepublishOnly": "expo-module prepublishOnly",
|
|
14
|
+
"expo-module": "expo-module",
|
|
15
|
+
"open:ios": "xed example/ios",
|
|
16
|
+
"open:android": "open -a \"Android Studio\" example/android"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"react-native",
|
|
20
|
+
"expo",
|
|
21
|
+
"expo-rotation-module",
|
|
22
|
+
"ExpoRotationModule"
|
|
23
|
+
],
|
|
24
|
+
"repository": "https://github.com/Ktsierra/expo-rotation-module",
|
|
25
|
+
"expo": {
|
|
26
|
+
"plugin": "./plugin/index.js"
|
|
27
|
+
},
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/Ktsierra/expo-rotation-module/issues"
|
|
30
|
+
},
|
|
31
|
+
"author": "Ktsierra <josejaviersierra1998@gmail.com> (https://github.com/Ktsierra)",
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"homepage": "https://github.com/Ktsierra/expo-rotation-module#readme",
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@expo/npm-proofread": "^1.0.1"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/react": "~19.1.0",
|
|
39
|
+
"expo": "^54.0.27",
|
|
40
|
+
"expo-module-scripts": "^5.0.8",
|
|
41
|
+
"react-native": "0.81.5"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"expo": "*",
|
|
45
|
+
"react": "*",
|
|
46
|
+
"react-native": "*"
|
|
47
|
+
}
|
|
48
|
+
}
|
package/plugin/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
let withAndroidManifest;
|
|
2
|
+
try {
|
|
3
|
+
// Prefer the project's installed config-plugins so resolution works from the app
|
|
4
|
+
withAndroidManifest = require(process.cwd() + '/node_modules/@expo/config-plugins').withAndroidManifest;
|
|
5
|
+
} catch (e) {
|
|
6
|
+
// Fallback to resolving from this package (useful for local dev)
|
|
7
|
+
withAndroidManifest = require('@expo/config-plugins').withAndroidManifest;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function addWriteSettingsPermission(androidManifest) {
|
|
11
|
+
const usesPermissions = androidManifest.manifest['uses-permission'] || [];
|
|
12
|
+
const exists = usesPermissions.some(
|
|
13
|
+
(p) => p.$['android:name'] === 'android.permission.WRITE_SETTINGS'
|
|
14
|
+
);
|
|
15
|
+
if (!exists) {
|
|
16
|
+
usesPermissions.push({
|
|
17
|
+
$: {
|
|
18
|
+
'android:name': 'android.permission.WRITE_SETTINGS',
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
androidManifest.manifest['uses-permission'] = usesPermissions;
|
|
22
|
+
}
|
|
23
|
+
return androidManifest;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
module.exports = function withWriteSettingsPermission(config) {
|
|
27
|
+
return withAndroidManifest(config, (config) => {
|
|
28
|
+
config.modResults = addWriteSettingsPermission(config.modResults);
|
|
29
|
+
return config;
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
module.exports.plugin = module.exports;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { NativeModule, requireNativeModule } from 'expo';
|
|
2
|
+
import { Platform } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import { ExpoRotationModuleEvents } from './ExpoRotationModule.types';
|
|
5
|
+
|
|
6
|
+
export type RotationState = 'AUTOROTATE' | 'PORTRAIT' | 'LANDSCAPE';
|
|
7
|
+
|
|
8
|
+
declare class ExpoRotationModule extends NativeModule<ExpoRotationModuleEvents> {
|
|
9
|
+
canWrite(): Promise<boolean>;
|
|
10
|
+
requestWritePermission(): void;
|
|
11
|
+
getRotationState(): Promise<RotationState>;
|
|
12
|
+
setRotationState(state: RotationState): Promise<void>;
|
|
13
|
+
getPackageName(): Promise<string>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// This call loads the native module object from the JSI on native platforms.
|
|
17
|
+
const isAndroid = Platform.OS === 'android';
|
|
18
|
+
const nativeModule = isAndroid ? requireNativeModule<ExpoRotationModule>('ExpoRotationModule') : null;
|
|
19
|
+
|
|
20
|
+
export async function canWrite(): Promise<boolean> {
|
|
21
|
+
if (!isAndroid || !nativeModule || !nativeModule.canWrite) return false;
|
|
22
|
+
try {
|
|
23
|
+
return await nativeModule.canWrite();
|
|
24
|
+
} catch (e: any) {
|
|
25
|
+
throw normalizeError(e);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function requestWritePermission(): void {
|
|
30
|
+
if (!isAndroid || !nativeModule || !nativeModule.requestWritePermission) return;
|
|
31
|
+
try {
|
|
32
|
+
nativeModule.requestWritePermission();
|
|
33
|
+
} catch (e: any) {
|
|
34
|
+
throw normalizeError(e);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function getPackageName(): Promise<string> {
|
|
39
|
+
if (!isAndroid || !nativeModule || !nativeModule.getPackageName) return '';
|
|
40
|
+
try {
|
|
41
|
+
return await nativeModule.getPackageName();
|
|
42
|
+
} catch (e: any) {
|
|
43
|
+
throw normalizeError(e);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function getRotationState(): Promise<RotationState> {
|
|
48
|
+
if (!isAndroid || !nativeModule || !nativeModule.getRotationState) return 'AUTOROTATE';
|
|
49
|
+
try {
|
|
50
|
+
return await nativeModule.getRotationState();
|
|
51
|
+
} catch (e: any) {
|
|
52
|
+
throw normalizeError(e);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function normalizeError(e: any): Error & { code?: string } {
|
|
57
|
+
const err = new Error(e?.message || String(e));
|
|
58
|
+
// Try to extract code from messages like "E_PERMISSION: ..."
|
|
59
|
+
const m = (e?.message || '').match(/^([A-Z_]+):\s*(.*)$/);
|
|
60
|
+
if (m) {
|
|
61
|
+
(err as any).code = m[1];
|
|
62
|
+
err.message = m[2] || err.message;
|
|
63
|
+
}
|
|
64
|
+
return err as Error & { code?: string };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export async function setRotationState(state: RotationState): Promise<void> {
|
|
68
|
+
if (!isAndroid || !nativeModule || !nativeModule.setRotationState) {
|
|
69
|
+
const err = new Error('Rotation native module not available') as Error & { code?: string };
|
|
70
|
+
err.code = 'E_NO_MODULE';
|
|
71
|
+
throw err;
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
return await nativeModule.setRotationState(state);
|
|
75
|
+
} catch (e: any) {
|
|
76
|
+
throw normalizeError(e);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export default {
|
|
81
|
+
canWrite,
|
|
82
|
+
requestWritePermission,
|
|
83
|
+
getRotationState,
|
|
84
|
+
setRotationState,
|
|
85
|
+
getPackageName,
|
|
86
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { StyleProp, ViewStyle } from 'react-native';
|
|
2
|
+
|
|
3
|
+
export type OnLoadEventPayload = {
|
|
4
|
+
url: string;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type ExpoRotationModuleEvents = {
|
|
8
|
+
onChange: (params: ChangeEventPayload) => void;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type ChangeEventPayload = {
|
|
12
|
+
value: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type ExpoRotationModuleViewProps = {
|
|
16
|
+
url: string;
|
|
17
|
+
onLoad: (event: { nativeEvent: OnLoadEventPayload }) => void;
|
|
18
|
+
style?: StyleProp<ViewStyle>;
|
|
19
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { registerWebModule, NativeModule } from 'expo';
|
|
2
|
+
|
|
3
|
+
import { ExpoRotationModuleEvents } from './ExpoRotationModule.types';
|
|
4
|
+
import type { RotationState } from './ExpoRotationModule';
|
|
5
|
+
|
|
6
|
+
class ExpoRotationModule extends NativeModule<ExpoRotationModuleEvents> {
|
|
7
|
+
async canWrite(): Promise<boolean> {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
requestWritePermission(): void {
|
|
11
|
+
// no-op on web
|
|
12
|
+
}
|
|
13
|
+
async getRotationState(): Promise<RotationState> {
|
|
14
|
+
return 'AUTOROTATE';
|
|
15
|
+
}
|
|
16
|
+
async setRotationState(state: RotationState): Promise<void> {
|
|
17
|
+
// no-op on web
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default registerWebModule(ExpoRotationModule, 'ExpoRotationModule');
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type RotationState = "AUTOROTATE" | "PORTRAIT" | "LANDSCAPE";
|
|
2
|
+
|
|
3
|
+
export function canWrite(): Promise<boolean>;
|
|
4
|
+
export function requestWritePermission(): void;
|
|
5
|
+
export function getRotationState(): Promise<RotationState>;
|
|
6
|
+
export function setRotationState(state: RotationState): Promise<void>;
|
|
7
|
+
export function getPackageName(): Promise<string>;
|
|
8
|
+
|
|
9
|
+
declare const _default: {
|
|
10
|
+
canWrite: typeof canWrite;
|
|
11
|
+
requestWritePermission: typeof requestWritePermission;
|
|
12
|
+
getRotationState: typeof getRotationState;
|
|
13
|
+
setRotationState: typeof setRotationState;
|
|
14
|
+
getPackageName: typeof getPackageName;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default _default;
|
package/src/index.ts
ADDED
package/tsconfig.json
ADDED