Skip to content

Commit f8a377a

Browse files
committed
feat: init commit
0 parents  commit f8a377a

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "react-native-is-multi-window",
3+
"version": "1.0.0",
4+
"description": "check if the current app is multiwindow",
5+
"main": "index.ts",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/wn-na/react-native-is-multi-window.git"
12+
},
13+
"keywords": [
14+
"react-native",
15+
"multiwindow"
16+
],
17+
"author": "wn-na",
18+
"license": "ISC",
19+
"bugs": {
20+
"url": "https://github.com/wn-na/react-native-is-multi-window/issues"
21+
},
22+
"homepage": "https://github.com/wn-na/react-native-is-multi-window#readme"
23+
}

src/index.tsx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { useEffect, useState } from "react";
2+
import { NativeEventEmitter, NativeModules, Platform } from "react-native";
3+
4+
const LINKING_ERROR =
5+
`The package 'react-native-is-multi-window' doesn't seem to be linked. Make sure: \n\n` +
6+
Platform.select({ ios: "- You have run 'pod install'\n", default: "" }) +
7+
"- You rebuilt the app after installing the package\n";
8+
9+
const ReactNativeIsMultiWindowModule = NativeModules.ReactNativeIsMultiWindow
10+
? NativeModules.ReactNativeIsMultiWindow
11+
: new Proxy(
12+
{},
13+
{
14+
get() {
15+
throw new Error(LINKING_ERROR);
16+
},
17+
}
18+
);
19+
20+
const ReactNativeIsMultiWindowEmitter = Platform.OS === "ios" || Platform.OS === "android" ? new NativeEventEmitter(ReactNativeIsMultiWindowModule) : undefined;
21+
22+
const addListener = (callback: (isMultiMode: boolean) => void): number => {
23+
return 0;
24+
};
25+
26+
const removeListener = (id: number) => {};
27+
28+
export const isMultiWindowMode = async () => {
29+
return true;
30+
};
31+
32+
export const useMultiWindowMode = () => {
33+
const [isMultiMode, setMultiMode] = useState(false);
34+
35+
useEffect(() => {
36+
isMultiWindowMode().then(setMultiMode);
37+
const listener = addListener((mode) => {
38+
setMultiMode(mode);
39+
});
40+
return () => {
41+
removeListener(listener);
42+
};
43+
}, []);
44+
45+
return { isMultiMode, isMultiWindowMode };
46+
};

0 commit comments

Comments
 (0)