@lodev09/react-native-true-sheet 0.9.8 → 0.10.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/README.md +9 -224
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetDialog.kt +25 -23
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetView.kt +25 -20
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetViewManager.kt +10 -0
- package/ios/TrueSheetView.swift +37 -45
- package/ios/TrueSheetViewController.swift +6 -2
- package/ios/TrueSheetViewManager.m +4 -0
- package/lib/commonjs/TrueSheet.js +79 -26
- package/lib/commonjs/TrueSheet.js.map +1 -1
- package/lib/commonjs/TrueSheetFooter.js +20 -0
- package/lib/commonjs/TrueSheetFooter.js.map +1 -0
- package/lib/commonjs/__mocks__/index.js +3 -0
- package/lib/commonjs/__mocks__/index.js.map +1 -1
- package/lib/module/TrueSheet.js +78 -25
- package/lib/module/TrueSheet.js.map +1 -1
- package/lib/module/TrueSheetFooter.js +12 -0
- package/lib/module/TrueSheetFooter.js.map +1 -0
- package/lib/module/__mocks__/index.js +3 -0
- package/lib/module/__mocks__/index.js.map +1 -1
- package/lib/typescript/docs/docusaurus.config.d.ts +4 -0
- package/lib/typescript/docs/docusaurus.config.d.ts.map +1 -0
- package/lib/typescript/docs/sidebars.d.ts +4 -0
- package/lib/typescript/docs/sidebars.d.ts.map +1 -0
- package/lib/typescript/src/TrueSheet.d.ts +27 -3
- package/lib/typescript/src/TrueSheet.d.ts.map +1 -1
- package/lib/typescript/src/TrueSheetFooter.d.ts +8 -0
- package/lib/typescript/src/TrueSheetFooter.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +15 -0
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/TrueSheet.tsx +102 -37
- package/src/TrueSheetFooter.tsx +18 -0
- package/src/__mocks__/index.js +4 -0
- package/src/types.ts +15 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TrueSheet.d.ts","sourceRoot":"","sources":["../../../src/TrueSheet.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,aAAa,EAAwC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"TrueSheet.d.ts","sourceRoot":"","sources":["../../../src/TrueSheet.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,aAAa,EAAwC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAYlG,OAAO,KAAK,EAAE,cAAc,EAAY,MAAM,SAAS,CAAA;AAsBvD,UAAU,cAAc;IACtB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAA;CAChC;AAQD,qBAAa,SAAU,SAAQ,aAAa,CAAC,cAAc,EAAE,cAAc,CAAC;IAC1E,WAAW,SAAc;IAEzB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAsB;IAE1C;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAiC;gBAEpD,KAAK,EAAE,cAAc;IAkBjC,OAAO,CAAC,MAAM,CAAC,SAAS;IAUxB;;;OAGG;WACiB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,GAAE,MAAU;IAO3D;;;OAGG;WACiB,OAAO,CAAC,IAAI,EAAE,MAAM;IAOxC;;;OAGG;WACiB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAItD,OAAO,KAAK,MAAM,GAOjB;IAED,OAAO,CAAC,WAAW;IAcnB,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,cAAc;IAOtB,OAAO,CAAC,eAAe;IAMvB,OAAO,CAAC,SAAS;IAIjB;;;OAGG;IACU,OAAO,CAAC,KAAK,GAAE,MAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAItD;;;OAGG;IACU,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjD;;OAEG;IACU,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrC,iBAAiB,IAAI,IAAI;IAUzB,kBAAkB,IAAI,IAAI;IAI1B,MAAM,IAAI,SAAS;CAmEpB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { TrueSheetProps } from './types';
|
|
3
|
+
interface TrueSheetFooterProps {
|
|
4
|
+
Component?: TrueSheetProps['FooterComponent'];
|
|
5
|
+
}
|
|
6
|
+
export declare const TrueSheetFooter: (props: TrueSheetFooterProps) => React.JSX.Element | null;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=TrueSheetFooter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TrueSheetFooter.d.ts","sourceRoot":"","sources":["../../../src/TrueSheetFooter.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,UAAU,oBAAoB;IAC5B,SAAS,CAAC,EAAE,cAAc,CAAC,iBAAiB,CAAC,CAAA;CAC9C;AAED,eAAO,MAAM,eAAe,UAAW,oBAAoB,6BAU1D,CAAA"}
|
|
@@ -61,6 +61,21 @@ export type SheetSize =
|
|
|
61
61
|
*/
|
|
62
62
|
| 'large';
|
|
63
63
|
export interface TrueSheetProps extends ViewProps {
|
|
64
|
+
/**
|
|
65
|
+
* The name to reference this sheet. It has to be unique.
|
|
66
|
+
* You can then present this sheet globally using its `name`.
|
|
67
|
+
*
|
|
68
|
+
* Example:
|
|
69
|
+
* ```ts
|
|
70
|
+
* <TrueSheet name="my-awesome-sheet">
|
|
71
|
+
* <MyComponent />
|
|
72
|
+
* </TrueSheet>
|
|
73
|
+
* ```
|
|
74
|
+
* ```ts
|
|
75
|
+
* TrueSheet.present('my-awesome-sheet')
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
name?: string;
|
|
64
79
|
/**
|
|
65
80
|
* The sizes you want the Sheet to support.
|
|
66
81
|
* Maximum of 3 sizes only; collapsed, half-expanded, expanded.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAC9E,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAE/E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAE/D,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;CACd;AAED;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAChB,OAAO,GACP,MAAM,GACN,SAAS,GACT,YAAY,GACZ,SAAS,GACT,WAAW,GACX,yBAAyB,GACzB,oBAAoB,GACpB,gBAAgB,GAChB,qBAAqB,GACrB,sBAAsB,GACtB,8BAA8B,GAC9B,yBAAyB,GACzB,qBAAqB,GACrB,0BAA0B,GAC1B,2BAA2B,GAC3B,6BAA6B,GAC7B,wBAAwB,GACxB,oBAAoB,GACpB,yBAAyB,GACzB,0BAA0B,CAAA;AAE9B;;;;;GAKG;AACH,MAAM,MAAM,SAAS;AACnB;;;;;GAKG;AACD,MAAM;AAER;;;;;GAKG;GACD,MAAM;AAER;;;;;GAKG;GACD,GAAG,MAAM,GAAG;AAEd;;;;;GAKG;GACD,OAAO;AAET;;;;;GAKG;GACD,QAAQ;AAEV;;;;;GAKG;GACD,OAAO,CAAA;AAEX,MAAM,WAAW,cAAe,SAAQ,SAAS;IAC/C;;;;;;;;;;OAUG;IACH,KA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zC;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB;;OAEG;IACH,eAAe,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,GAAG,YAAY,CAAA;IAEvD;;;OAGG;IACH,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,CAAA;IAEpC;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;IAEtB;;;OAGG;IACH,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,CAAA;CACxC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lodev09/react-native-true-sheet",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "The true native bottom sheet.
|
|
3
|
+
"version": "0.10.0",
|
|
4
|
+
"description": "The true native bottom sheet experience for your React Native Apps.",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
7
7
|
"types": "lib/typescript/src/index.d.ts",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
],
|
|
27
27
|
"scripts": {
|
|
28
28
|
"example": "yarn workspace true-sheet-example",
|
|
29
|
+
"docs": "yarn workspace docs",
|
|
29
30
|
"test": "jest",
|
|
30
31
|
"typecheck": "tsc --noEmit",
|
|
31
32
|
"lint": "eslint --fix \"**/*.{js,ts,tsx}\"",
|
|
@@ -90,14 +91,17 @@
|
|
|
90
91
|
"react-native": "*"
|
|
91
92
|
},
|
|
92
93
|
"workspaces": [
|
|
93
|
-
"example"
|
|
94
|
+
"example",
|
|
95
|
+
"docs"
|
|
94
96
|
],
|
|
95
97
|
"packageManager": "yarn@4.1.1",
|
|
96
98
|
"jest": {
|
|
97
99
|
"preset": "react-native",
|
|
98
100
|
"modulePathIgnorePatterns": [
|
|
99
101
|
"<rootDir>/example/node_modules",
|
|
100
|
-
"<rootDir>/
|
|
102
|
+
"<rootDir>/docs/node_modules",
|
|
103
|
+
"<rootDir>/lib/",
|
|
104
|
+
"<rootDir>/docs/build"
|
|
101
105
|
]
|
|
102
106
|
},
|
|
103
107
|
"commitlint": {
|
|
@@ -129,10 +133,6 @@
|
|
|
129
133
|
},
|
|
130
134
|
"eslintConfig": {
|
|
131
135
|
"root": true,
|
|
132
|
-
"ignorePatterns": [
|
|
133
|
-
"lib",
|
|
134
|
-
"src/__mocks__"
|
|
135
|
-
],
|
|
136
136
|
"extends": [
|
|
137
137
|
"plugin:@typescript-eslint/recommended",
|
|
138
138
|
"eslint:recommended",
|
package/src/TrueSheet.tsx
CHANGED
|
@@ -7,43 +7,53 @@ import {
|
|
|
7
7
|
type NativeMethods,
|
|
8
8
|
type ViewStyle,
|
|
9
9
|
type NativeSyntheticEvent,
|
|
10
|
+
type LayoutRectangle,
|
|
10
11
|
} from 'react-native'
|
|
11
12
|
|
|
12
13
|
import type { TrueSheetProps, SizeInfo } from './types'
|
|
13
14
|
import { TrueSheetModule } from './TrueSheetModule'
|
|
14
15
|
import { TrueSheetGrabber } from './TrueSheetGrabber'
|
|
16
|
+
import { TrueSheetFooter } from './TrueSheetFooter'
|
|
15
17
|
|
|
18
|
+
const NATIVE_COMPONENT_NAME = 'TrueSheetView'
|
|
16
19
|
const LINKING_ERROR =
|
|
17
20
|
`The package '@lodev09/react-native-true-sheet' doesn't seem to be linked. Make sure: \n\n` +
|
|
18
21
|
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
19
22
|
'- You rebuilt the app after installing the package\n' +
|
|
20
23
|
'- You are not using Expo Go\n'
|
|
21
24
|
|
|
22
|
-
const ComponentName = 'TrueSheetView'
|
|
23
|
-
|
|
24
25
|
interface TrueSheetNativeViewProps extends Omit<TrueSheetProps, 'onPresent' | 'onSizeChange'> {
|
|
26
|
+
contentHeight?: number
|
|
27
|
+
footerHeight?: number
|
|
25
28
|
scrollableHandle: number | null
|
|
26
29
|
onPresent: (event: NativeSyntheticEvent<SizeInfo>) => void
|
|
27
30
|
onSizeChange: (event: NativeSyntheticEvent<SizeInfo>) => void
|
|
28
31
|
}
|
|
29
32
|
|
|
30
|
-
const TrueSheetNativeView = requireNativeComponent<TrueSheetNativeViewProps>(ComponentName)
|
|
31
|
-
|
|
32
|
-
if (!TrueSheetNativeView) {
|
|
33
|
-
throw new Error(LINKING_ERROR)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
33
|
type NativeRef = Component<TrueSheetNativeViewProps> & Readonly<NativeMethods>
|
|
37
34
|
|
|
38
35
|
interface TrueSheetState {
|
|
36
|
+
contentHeight?: number
|
|
37
|
+
footerHeight?: number
|
|
39
38
|
scrollableHandle: number | null
|
|
40
39
|
}
|
|
41
40
|
|
|
41
|
+
const TrueSheetNativeView = requireNativeComponent<TrueSheetNativeViewProps>(NATIVE_COMPONENT_NAME)
|
|
42
|
+
|
|
43
|
+
if (!TrueSheetNativeView) {
|
|
44
|
+
throw new Error(LINKING_ERROR)
|
|
45
|
+
}
|
|
46
|
+
|
|
42
47
|
export class TrueSheet extends PureComponent<TrueSheetProps, TrueSheetState> {
|
|
43
48
|
displayName = 'TrueSheet'
|
|
44
49
|
|
|
45
50
|
private readonly ref: RefObject<NativeRef>
|
|
46
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Map of sheet names against their handle.
|
|
54
|
+
*/
|
|
55
|
+
private static readonly handles: { [name: string]: number } = {}
|
|
56
|
+
|
|
47
57
|
constructor(props: TrueSheetProps) {
|
|
48
58
|
super(props)
|
|
49
59
|
|
|
@@ -52,16 +62,60 @@ export class TrueSheet extends PureComponent<TrueSheetProps, TrueSheetState> {
|
|
|
52
62
|
this.onDismiss = this.onDismiss.bind(this)
|
|
53
63
|
this.onPresent = this.onPresent.bind(this)
|
|
54
64
|
this.onSizeChange = this.onSizeChange.bind(this)
|
|
65
|
+
this.onContentLayout = this.onContentLayout.bind(this)
|
|
66
|
+
this.onFooterLayout = this.onFooterLayout.bind(this)
|
|
55
67
|
|
|
56
68
|
this.state = {
|
|
69
|
+
contentHeight: undefined,
|
|
70
|
+
footerHeight: undefined,
|
|
57
71
|
scrollableHandle: null,
|
|
58
72
|
}
|
|
59
73
|
}
|
|
60
74
|
|
|
75
|
+
private static getHandle(name: string) {
|
|
76
|
+
const handle = TrueSheet.handles[name]
|
|
77
|
+
if (!handle) {
|
|
78
|
+
console.warn(`Could not get native view tag from "${name}". Check your name prop.`)
|
|
79
|
+
return
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return handle
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Present the sheet by given `name`.
|
|
87
|
+
* See `name` prop.
|
|
88
|
+
*/
|
|
89
|
+
public static async present(name: string, index: number = 0) {
|
|
90
|
+
const handle = TrueSheet.getHandle(name)
|
|
91
|
+
if (!handle) return
|
|
92
|
+
|
|
93
|
+
await TrueSheetModule.present(handle, index)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Dismiss the sheet by given `name`.
|
|
98
|
+
* See `name` prop.
|
|
99
|
+
*/
|
|
100
|
+
public static async dismiss(name: string) {
|
|
101
|
+
const handle = TrueSheet.getHandle(name)
|
|
102
|
+
if (!handle) return
|
|
103
|
+
|
|
104
|
+
await TrueSheetModule.dismiss(handle)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Resize the sheet by given `name`.
|
|
109
|
+
* See `name` prop.
|
|
110
|
+
*/
|
|
111
|
+
public static async resize(name: string, index: number) {
|
|
112
|
+
await TrueSheet.present(name, index)
|
|
113
|
+
}
|
|
114
|
+
|
|
61
115
|
private get handle(): number {
|
|
62
116
|
const nodeHandle = findNodeHandle(this.ref.current)
|
|
63
117
|
if (nodeHandle == null || nodeHandle === -1) {
|
|
64
|
-
throw new Error(
|
|
118
|
+
throw new Error('Could not get native view tag')
|
|
65
119
|
}
|
|
66
120
|
|
|
67
121
|
return nodeHandle
|
|
@@ -72,6 +126,10 @@ export class TrueSheet extends PureComponent<TrueSheetProps, TrueSheetState> {
|
|
|
72
126
|
? findNodeHandle(this.props.scrollRef.current)
|
|
73
127
|
: null
|
|
74
128
|
|
|
129
|
+
if (this.props.name) {
|
|
130
|
+
TrueSheet.handles[this.props.name] = this.handle
|
|
131
|
+
}
|
|
132
|
+
|
|
75
133
|
this.setState({
|
|
76
134
|
scrollableHandle,
|
|
77
135
|
})
|
|
@@ -85,26 +143,25 @@ export class TrueSheet extends PureComponent<TrueSheetProps, TrueSheetState> {
|
|
|
85
143
|
this.props.onPresent?.(event.nativeEvent)
|
|
86
144
|
}
|
|
87
145
|
|
|
88
|
-
private
|
|
89
|
-
|
|
146
|
+
private onFooterLayout(layout: LayoutRectangle): void {
|
|
147
|
+
console.log('footerHeight', layout.height)
|
|
148
|
+
this.setState({
|
|
149
|
+
footerHeight: layout.height,
|
|
150
|
+
})
|
|
90
151
|
}
|
|
91
152
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
)
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
this.updateState()
|
|
153
|
+
private onContentLayout(layout: LayoutRectangle): void {
|
|
154
|
+
this.setState({
|
|
155
|
+
contentHeight: layout.height,
|
|
156
|
+
})
|
|
100
157
|
}
|
|
101
158
|
|
|
102
|
-
|
|
103
|
-
this.
|
|
159
|
+
private onDismiss(): void {
|
|
160
|
+
this.props.onDismiss?.()
|
|
104
161
|
}
|
|
105
162
|
|
|
106
163
|
/**
|
|
107
|
-
* Present the
|
|
164
|
+
* Present the sheet. Optionally accepts a size `index`.
|
|
108
165
|
* See `sizes` prop
|
|
109
166
|
*/
|
|
110
167
|
public async present(index: number = 0): Promise<void> {
|
|
@@ -126,6 +183,20 @@ export class TrueSheet extends PureComponent<TrueSheetProps, TrueSheetState> {
|
|
|
126
183
|
await TrueSheetModule.dismiss(this.handle)
|
|
127
184
|
}
|
|
128
185
|
|
|
186
|
+
componentDidMount(): void {
|
|
187
|
+
if (this.props.sizes && this.props.sizes.length > 3) {
|
|
188
|
+
console.warn(
|
|
189
|
+
'TrueSheet only supports a maximum of 3 sizes; collapsed, half-expanded and expanded. Check your `sizes` prop.'
|
|
190
|
+
)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
this.updateState()
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
componentDidUpdate(): void {
|
|
197
|
+
this.updateState()
|
|
198
|
+
}
|
|
199
|
+
|
|
129
200
|
render(): ReactNode {
|
|
130
201
|
const {
|
|
131
202
|
sizes = ['medium', 'large'],
|
|
@@ -151,6 +222,8 @@ export class TrueSheet extends PureComponent<TrueSheetProps, TrueSheetState> {
|
|
|
151
222
|
sizes={sizes}
|
|
152
223
|
blurTint={blurTint}
|
|
153
224
|
cornerRadius={cornerRadius}
|
|
225
|
+
contentHeight={this.state.contentHeight}
|
|
226
|
+
footerHeight={this.state.footerHeight}
|
|
154
227
|
grabber={grabber}
|
|
155
228
|
dismissible={dismissible}
|
|
156
229
|
maxHeight={maxHeight}
|
|
@@ -176,11 +249,15 @@ export class TrueSheet extends PureComponent<TrueSheetProps, TrueSheetState> {
|
|
|
176
249
|
]}
|
|
177
250
|
{...rest}
|
|
178
251
|
>
|
|
179
|
-
<View
|
|
252
|
+
<View
|
|
253
|
+
collapsable={false}
|
|
254
|
+
onLayout={(e) => this.onContentLayout(e.nativeEvent.layout)}
|
|
255
|
+
style={contentContainerStyle}
|
|
256
|
+
>
|
|
180
257
|
{children}
|
|
181
258
|
</View>
|
|
182
|
-
<View collapsable={false}>
|
|
183
|
-
<TrueSheetFooter
|
|
259
|
+
<View collapsable={false} onLayout={(e) => this.onFooterLayout(e.nativeEvent.layout)}>
|
|
260
|
+
<TrueSheetFooter Component={FooterComponent} />
|
|
184
261
|
</View>
|
|
185
262
|
{Platform.OS === 'android' && <TrueSheetGrabber visible={grabber} {...grabberProps} />}
|
|
186
263
|
</View>
|
|
@@ -189,18 +266,6 @@ export class TrueSheet extends PureComponent<TrueSheetProps, TrueSheetState> {
|
|
|
189
266
|
}
|
|
190
267
|
}
|
|
191
268
|
|
|
192
|
-
const TrueSheetFooter = (props: Pick<TrueSheetProps, 'FooterComponent'>) => {
|
|
193
|
-
const { FooterComponent } = props
|
|
194
|
-
|
|
195
|
-
if (!FooterComponent) return null
|
|
196
|
-
|
|
197
|
-
if (typeof FooterComponent !== 'function') {
|
|
198
|
-
return FooterComponent
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
return <FooterComponent />
|
|
202
|
-
}
|
|
203
|
-
|
|
204
269
|
const $nativeSheet: ViewStyle = {
|
|
205
270
|
position: 'absolute',
|
|
206
271
|
left: -9999,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import type { TrueSheetProps } from './types'
|
|
3
|
+
|
|
4
|
+
interface TrueSheetFooterProps {
|
|
5
|
+
Component?: TrueSheetProps['FooterComponent']
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const TrueSheetFooter = (props: TrueSheetFooterProps) => {
|
|
9
|
+
const { Component } = props
|
|
10
|
+
|
|
11
|
+
if (!Component) return null
|
|
12
|
+
|
|
13
|
+
if (typeof Component !== 'function') {
|
|
14
|
+
return Component
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return <Component />
|
|
18
|
+
}
|
package/src/__mocks__/index.js
CHANGED
|
@@ -4,6 +4,10 @@ import { View } from 'react-native'
|
|
|
4
4
|
export * from '../TrueSheetGrabber'
|
|
5
5
|
|
|
6
6
|
export class TrueSheet extends React.Component {
|
|
7
|
+
static dismiss = jest.fn()
|
|
8
|
+
static present = jest.fn()
|
|
9
|
+
static resize = jest.fn()
|
|
10
|
+
|
|
7
11
|
dismiss = jest.fn()
|
|
8
12
|
present = jest.fn()
|
|
9
13
|
resize = jest.fn()
|
package/src/types.ts
CHANGED
|
@@ -92,6 +92,21 @@ export type SheetSize =
|
|
|
92
92
|
| 'large'
|
|
93
93
|
|
|
94
94
|
export interface TrueSheetProps extends ViewProps {
|
|
95
|
+
/**
|
|
96
|
+
* The name to reference this sheet. It has to be unique.
|
|
97
|
+
* You can then present this sheet globally using its `name`.
|
|
98
|
+
*
|
|
99
|
+
* Example:
|
|
100
|
+
* ```ts
|
|
101
|
+
* <TrueSheet name="my-awesome-sheet">
|
|
102
|
+
* <MyComponent />
|
|
103
|
+
* </TrueSheet>
|
|
104
|
+
* ```
|
|
105
|
+
* ```ts
|
|
106
|
+
* TrueSheet.present('my-awesome-sheet')
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
name?: string
|
|
95
110
|
/**
|
|
96
111
|
* The sizes you want the Sheet to support.
|
|
97
112
|
* Maximum of 3 sizes only; collapsed, half-expanded, expanded.
|