@lodev09/react-native-true-sheet 0.4.4 → 0.5.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/src/TrueSheet.tsx CHANGED
@@ -7,10 +7,9 @@ import {
7
7
  type NativeMethods,
8
8
  type ViewStyle,
9
9
  type NativeSyntheticEvent,
10
- type StyleProp,
11
10
  } from 'react-native'
12
11
 
13
- import type { TrueSheetProps, SizeChangeEvent } from './types'
12
+ import type { TrueSheetProps, SizeInfo } from './types'
14
13
  import { TrueSheetModule } from './TrueSheetModule'
15
14
 
16
15
  const LINKING_ERROR =
@@ -21,15 +20,10 @@ const LINKING_ERROR =
21
20
 
22
21
  const ComponentName = 'TrueSheetView'
23
22
 
24
- interface TrueSheetNativeViewProps {
23
+ interface TrueSheetNativeViewProps extends Omit<TrueSheetProps, 'onPresent' | 'onSizeChange'> {
25
24
  scrollableHandle: number | null
26
- style: StyleProp<ViewStyle>
27
- sizes: TrueSheetProps['sizes']
28
- maxHeight?: TrueSheetProps['maxHeight']
29
- children: ReactNode
30
- onDismiss: () => void
31
- onPresent: (event: NativeSyntheticEvent<{ index: number }>) => void
32
- onSizeChange: (event: NativeSyntheticEvent<SizeChangeEvent>) => void
25
+ onPresent: (event: NativeSyntheticEvent<SizeInfo>) => void
26
+ onSizeChange: (event: NativeSyntheticEvent<SizeInfo>) => void
33
27
  }
34
28
 
35
29
  const TrueSheetNativeView = requireNativeComponent<TrueSheetNativeViewProps>(ComponentName)
@@ -82,12 +76,12 @@ export class TrueSheet extends PureComponent<TrueSheetProps, TrueSheetState> {
82
76
  })
83
77
  }
84
78
 
85
- private onSizeChange(event: NativeSyntheticEvent<SizeChangeEvent>) {
79
+ private onSizeChange(event: NativeSyntheticEvent<SizeInfo>) {
86
80
  this.props.onSizeChange?.(event.nativeEvent)
87
81
  }
88
82
 
89
- private onPresent(): void {
90
- this.props.onPresent?.()
83
+ private onPresent(event: NativeSyntheticEvent<SizeInfo>): void {
84
+ this.props.onPresent?.(event.nativeEvent)
91
85
  }
92
86
 
93
87
  private onDismiss(): void {
@@ -117,32 +111,61 @@ export class TrueSheet extends PureComponent<TrueSheetProps, TrueSheetState> {
117
111
  }
118
112
 
119
113
  /**
120
- * Dismiss the Sheet
114
+ * Dismisses the Sheet
121
115
  */
122
116
  public async dismiss() {
123
117
  await TrueSheetModule.dismiss(this.handle)
124
118
  }
125
119
 
126
120
  render(): ReactNode {
127
- const FooterComponent = this.props.FooterComponent
121
+ const {
122
+ sizes,
123
+ backgroundColor,
124
+ blurStyle,
125
+ cornerRadius,
126
+ grabber,
127
+ maxHeight,
128
+ FooterComponent,
129
+ testID,
130
+ style,
131
+ children,
132
+ ...rest
133
+ } = this.props
128
134
 
129
135
  return (
130
136
  <TrueSheetNativeView
131
137
  ref={this.ref}
132
138
  style={$nativeSheet}
133
139
  scrollableHandle={this.state.scrollableHandle}
134
- sizes={this.props.sizes ?? ['medium', 'large']}
135
- maxHeight={this.props.maxHeight}
140
+ sizes={sizes ?? ['medium', 'large']}
141
+ blurStyle={blurStyle}
142
+ cornerRadius={cornerRadius}
143
+ grabber={grabber ?? true}
144
+ maxHeight={maxHeight}
136
145
  onPresent={this.onPresent}
137
146
  onDismiss={this.onDismiss}
138
147
  onSizeChange={this.onSizeChange}
148
+ testID={testID}
139
149
  >
140
150
  <View
141
151
  collapsable={false}
142
- style={{ backgroundColor: this.props.backgroundColor ?? 'white' }}
152
+ style={[
153
+ $sheetWrapper,
154
+ {
155
+ borderTopLeftRadius: cornerRadius,
156
+ borderTopRightRadius: cornerRadius,
157
+
158
+ // Remove backgroundColor if `blurStyle` is set on iOS
159
+ backgroundColor: Platform.select({
160
+ ios: blurStyle ? undefined : backgroundColor ?? 'white',
161
+ android: backgroundColor ?? 'white',
162
+ }),
163
+ },
164
+ ]}
165
+ {...rest}
143
166
  >
144
- <View collapsable={false} style={this.props.style}>
145
- {this.props.children}
167
+ <View collapsable={false} style={style}>
168
+ {children}
146
169
  </View>
147
170
  <View collapsable={false}>{!!FooterComponent && <FooterComponent />}</View>
148
171
  </View>
@@ -153,5 +176,10 @@ export class TrueSheet extends PureComponent<TrueSheetProps, TrueSheetState> {
153
176
 
154
177
  const $nativeSheet: ViewStyle = {
155
178
  position: 'absolute',
179
+ width: 0,
156
180
  zIndex: -9999,
157
181
  }
182
+
183
+ const $sheetWrapper: ViewStyle = {
184
+ overflow: 'hidden',
185
+ }
@@ -1,7 +1,7 @@
1
1
  import React from 'react'
2
2
  import { View } from 'react-native'
3
3
 
4
- export default class TrueSheet extends React.Component {
4
+ export class TrueSheet extends React.Component {
5
5
  dismiss = jest.fn()
6
6
  present = jest.fn()
7
7
 
package/src/types.ts CHANGED
@@ -1,14 +1,44 @@
1
1
  import type { Component, ComponentType, RefObject } from 'react'
2
2
  import type { ColorValue, ViewProps } from 'react-native'
3
3
 
4
- export interface SizeChangeEvent {
4
+ export interface SizeInfo {
5
5
  index: number
6
6
  value: number
7
7
  }
8
8
 
9
+ /**
10
+ * Blur style mapped to native values in IOS.
11
+ *
12
+ * @platform ios
13
+ */
14
+ export type BlurStyle =
15
+ | 'light'
16
+ | 'dark'
17
+ | 'default'
18
+ | 'extraLight'
19
+ | 'regular'
20
+ | 'prominent'
21
+ | 'systemUltraThinMaterial'
22
+ | 'systemThinMaterial'
23
+ | 'systemMaterial'
24
+ | 'systemThickMaterial'
25
+ | 'systemChromeMaterial'
26
+ | 'systemUltraThinMaterialLight'
27
+ | 'systemThinMaterialLight'
28
+ | 'systemMaterialLight'
29
+ | 'systemThickMaterialLight'
30
+ | 'systemChromeMaterialLight'
31
+ | 'systemUltraThinMaterialDark'
32
+ | 'systemThinMaterialDark'
33
+ | 'systemMaterialDark'
34
+ | 'systemThickMaterialDark'
35
+ | 'systemChromeMaterialDark'
36
+
9
37
  /**
10
38
  * Supported Sheet size.
11
- * Requires IOS 15+
39
+ *
40
+ * @platform android
41
+ * @platform ios 15+
12
42
  */
13
43
  export type SheetSize =
14
44
  /**
@@ -60,29 +90,54 @@ export type SheetSize =
60
90
  | 'large'
61
91
 
62
92
  export interface TrueSheetProps extends ViewProps {
93
+ /**
94
+ * The sizes you want the Sheet to support.
95
+ * Maximum of 3 sizes only; collapsed, half-expanded, expanded.
96
+ *
97
+ * Example:
98
+ * ```ts
99
+ * size={['auto', '60%', 'large']}
100
+ * ```
101
+ *
102
+ * @default ['medium', 'large']
103
+ */
104
+ sizes?: SheetSize[]
105
+
63
106
  /**
64
107
  * Main sheet background color
65
108
  */
66
109
  backgroundColor?: ColorValue
67
110
 
68
111
  /**
69
- * The main scrollable ref that Sheet should handle on IOS.
112
+ * The sheet corner radius.
113
+ *
114
+ * @platform android
115
+ * @platform ios 15+
116
+ */
117
+ cornerRadius?: number
118
+
119
+ /**
120
+ * Shows native grabber (or handle) on IOS
121
+ *
70
122
  * @platform ios
123
+ * @default true
71
124
  */
72
- scrollRef?: RefObject<Component<unknown>>
125
+ grabber?: boolean
73
126
 
74
127
  /**
75
- * The sizes you want the Sheet to support.
76
- * Maximum of 3 sizes only; collapsed, half-expanded, expanded.
128
+ * The blur effect style on iOS.
129
+ * Overrides `backgroundColor` if set.
77
130
  *
78
- * Example:
79
- * ```ts
80
- * size={['auto', '60%', 'large']}
81
- * ```
131
+ * @platform ios
132
+ */
133
+ blurStyle?: BlurStyle
134
+
135
+ /**
136
+ * The main scrollable ref that Sheet should handle on IOS.
82
137
  *
83
- * @default ['medium', 'large']
138
+ * @platform ios
84
139
  */
85
- sizes?: SheetSize[]
140
+ scrollRef?: RefObject<Component<unknown>>
86
141
 
87
142
  /**
88
143
  * Overrides `large` or `100%` height.
@@ -96,9 +151,9 @@ export interface TrueSheetProps extends ViewProps {
96
151
 
97
152
  /**
98
153
  * Called when the Sheet has been presented.
99
- * Comes with the size index.
154
+ * Comes with the size info.
100
155
  */
101
- onPresent?: () => void
156
+ onPresent?: (info: SizeInfo) => void
102
157
 
103
158
  /**
104
159
  * Called when the Sheet has been dismissed
@@ -109,5 +164,5 @@ export interface TrueSheetProps extends ViewProps {
109
164
  * Called when the size of the sheet has changed.
110
165
  * Either by dragging or programatically.
111
166
  */
112
- onSizeChange?: (event: SizeChangeEvent) => void
167
+ onSizeChange?: (info: SizeInfo) => void
113
168
  }
@@ -1 +0,0 @@
1
- {"version":3,"names":["_react","_interopRequireDefault","require","_reactNative","obj","__esModule","default","TrueSheet","React","Component","dismiss","jest","fn","present","render","createElement","View","props","exports"],"sourceRoot":"../../../src","sources":["__mocks__/TrueSheet.js"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAAmC,SAAAD,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAEpB,MAAMG,SAAS,SAASC,cAAK,CAACC,SAAS,CAAC;EACrDC,OAAO,GAAGC,IAAI,CAACC,EAAE,CAAC,CAAC;EACnBC,OAAO,GAAGF,IAAI,CAACC,EAAE,CAAC,CAAC;EAEnBE,MAAMA,CAAA,EAAG;IACP,oBAAOd,MAAA,CAAAM,OAAA,CAAAS,aAAA,CAACZ,YAAA,CAAAa,IAAI,EAAK,IAAI,CAACC,KAAQ,CAAC;EACjC;AACF;AAACC,OAAA,CAAAZ,OAAA,GAAAC,SAAA","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":["React","View","TrueSheet","Component","dismiss","jest","fn","present","render","createElement","props"],"sourceRoot":"../../../src","sources":["__mocks__/TrueSheet.js"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,IAAI,QAAQ,cAAc;AAEnC,eAAe,MAAMC,SAAS,SAASF,KAAK,CAACG,SAAS,CAAC;EACrDC,OAAO,GAAGC,IAAI,CAACC,EAAE,CAAC,CAAC;EACnBC,OAAO,GAAGF,IAAI,CAACC,EAAE,CAAC,CAAC;EAEnBE,MAAMA,CAAA,EAAG;IACP,oBAAOR,KAAA,CAAAS,aAAA,CAACR,IAAI,EAAK,IAAI,CAACS,KAAQ,CAAC;EACjC;AACF","ignoreList":[]}