Skip to content

Commit fd64419

Browse files
authored
Merge pull request #17 from logicwind/dev
Dev
2 parents 87120bf + f4fab5d commit fd64419

File tree

3 files changed

+36
-9
lines changed

3 files changed

+36
-9
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## 0.3.2
2+
3+
- Fix: Invalid hook call ([#14](https://github.com/logicwind/react-native-fold-detection/issues/14))
4+
5+
## 0.3.1
6+
7+
- Fix: Ios build issue on react-native version 0.76.0
8+
9+
## 0.3.0
10+
11+
- Fixed null pointer exception error on startListener.
12+
- Added detection for only fold devices will register for the listener.
13+
14+
## 0.2.0
15+
16+
- Read me updated
17+
- Example updated
18+
19+
## 0.1.0
20+
21+
- Initial Release

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@logicwind/react-native-fold-detection",
3-
"version": "0.3.1",
3+
"version": "0.3.2",
44
"description": "The purpose of the package is to provide details regarding the Android folding capability.",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",
@@ -170,4 +170,4 @@
170170
]
171171
]
172172
}
173-
}
173+
}

src/context/FoldingFeatureContext.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ export const FoldingFeatureContext = createContext<FoldingFeatureContextProps>({
3838
});
3939

4040
export const useFoldingFeature = () => {
41+
const context = useContext(FoldingFeatureContext);
42+
43+
if (context === undefined) {
44+
throw new Error('useFoldingFeature was used outside of its provider');
45+
}
46+
4147
if (Platform.OS === 'ios') {
4248
return {
4349
layoutInfo: {},
@@ -46,20 +52,16 @@ export const useFoldingFeature = () => {
4652
isFlat: true,
4753
};
4854
}
49-
const context = useContext(FoldingFeatureContext);
50-
51-
if (context === undefined) {
52-
throw new Error('useFoldingFeature was used outside of its provider');
53-
}
54-
55+
5556
return context;
5657
};
5758

5859
export const FoldingFeatureProvider = ({ children }: PropsWithChildren<{}>) => {
60+
const value = useProvideFunc();
61+
5962
if (Platform.OS === 'ios') {
6063
return children;
6164
}
62-
const value = useProvideFunc();
6365

6466
return (
6567
<FoldingFeatureContext.Provider value={value}>
@@ -100,6 +102,10 @@ const useProvideFunc = (): FoldingFeatureContextProps => {
100102
}, [isTableTop, isBook]);
101103

102104
useEffect(() => {
105+
if (Platform.OS === 'ios') {
106+
return; // Just return early from the effect
107+
}
108+
103109
FoldingFeature.startListening();
104110

105111
const eventEmitter = new NativeEventEmitter();

0 commit comments

Comments
 (0)