Skip to content

Commit 08e018d

Browse files
authored
49 - add ref support to withTheme HOC (#916)
* add ref support to withTheme HOC * update bottomsheet
1 parent d0e0632 commit 08e018d

File tree

3 files changed

+43
-8
lines changed

3 files changed

+43
-8
lines changed

example/src/BottomSheetExample.tsx

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,47 @@
11
import React from "react";
22
import { Text, View } from "react-native";
33
import { BottomSheet } from "@draftbit/ui";
4+
import { Button } from "@draftbit/core";
45

56
const BottomSheetExample: React.FC = () => {
7+
const bottomSheetRef = React.useRef<any>();
68
return (
79
<View style={{ flex: 1 }}>
8-
<BottomSheet style={{ alignItems: "center" }}>
10+
<BottomSheet style={{ alignItems: "center" }} ref={bottomSheetRef}>
911
<Text>This is a bottom Sheet</Text>
1012
</BottomSheet>
13+
<Button
14+
title="Expand"
15+
onPress={() => {
16+
if (bottomSheetRef && bottomSheetRef?.current) {
17+
bottomSheetRef?.current?.expand();
18+
}
19+
}}
20+
/>
21+
<Button
22+
title="Snap to index 2"
23+
onPress={() => {
24+
if (bottomSheetRef && bottomSheetRef?.current) {
25+
bottomSheetRef?.current?.snapToIndex(2);
26+
}
27+
}}
28+
/>
29+
<Button
30+
title="Collapse"
31+
onPress={() => {
32+
if (bottomSheetRef && bottomSheetRef?.current) {
33+
bottomSheetRef?.current?.collapse();
34+
}
35+
}}
36+
/>
37+
<Button
38+
title="Close"
39+
onPress={() => {
40+
if (bottomSheetRef && bottomSheetRef?.current) {
41+
bottomSheetRef?.current?.close();
42+
}
43+
}}
44+
/>
1145
</View>
1246
);
1347
};

packages/core/src/components/BottomSheet/BottomSheet.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import BottomSheetComponent, {
1111
BottomSheetScrollView,
1212
} from "@gorhom/bottom-sheet";
1313
import type { ReadTheme } from "@draftbit/theme";
14-
import { withTheme } from "@draftbit/theme";
1514
import { useDeepCompareMemo } from "../../utilities";
1615

1716
type SnapPosition = "top" | "middle" | "bottom";
@@ -166,4 +165,4 @@ const styles = StyleSheet.create({
166165
},
167166
});
168167

169-
export default withTheme(BottomSheet);
168+
export default BottomSheet;

packages/theme/src/Provider.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,13 @@ const useChangeTheme = (): ((themeName: string) => void) => {
117117

118118
const withTheme = <Props extends { theme: ReadTheme }>(
119119
Component: React.ComponentType<Props>
120-
): React.ComponentType<Omit<Props, "theme">> => {
121-
return (props: Omit<Props, "theme">) => {
122-
const { theme } = React.useContext(ThemeContext);
123-
return <Component {...(props as Props)} theme={theme} />;
124-
};
120+
) => {
121+
return React.forwardRef(
122+
(props: Omit<Props, "theme">, ref: React.Ref<any>) => {
123+
const { theme } = React.useContext(ThemeContext);
124+
return <Component {...(props as Props)} theme={theme} ref={ref} />;
125+
}
126+
);
125127
};
126128

127129
export { Provider, useTheme, useChangeTheme, withTheme };

0 commit comments

Comments
 (0)