You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -109,7 +109,7 @@ The example app is running from [`./example/App.tsx`](./example/App.tsx)
109
109
|`sensitivity`|`number`|`10`| The amount of pixels a drawer needs to slide to trigger state change (peek to open or open to peek). The smaller the value, the more sensitive the state change. Default to 10. |
110
110
|`expandable`|`boolean`|`true`| A flag indicating whether a drawer is static (non-expandable) or dynamic (expandable). Default to true, i.e. the drawer is dynamic. |
111
111
|`isInitialPeek`|`boolean`|`true`| A flag indicating whether the initial state of the drawer is peek or open. Default to true, i.e. the initial state is peek. |
112
-
|`enableSlideOpen`|`boolean`|`true`| A flag indicating whether a drawer can be opened with sliding (e.g. open upon a button press). Default to true. |
112
+
|`enableSlideOpen`|`boolean`|`true`| A flag indicating whether a drawer can be opened with sliding. Default to true. |
113
113
|`enableNonSlideOpen`|`boolean`|`false`| A flag indicating whether a drawer can be opened without sliding (e.g. open upon a button press). Default to false. |
114
114
|`nonSlideOpen`|`boolean`|`false`| A flag indicating whether to open or close a drawer. Applicable only when `enableNonSlideOpen` is set to true. Default to false, i.e. to close the drawer. |
115
115
|`onDrawerOpen`|`() => void`|`() => {}`| A callback function when the drawer reaches the open state. See the caveat section for the particularity of its usage. Default to a no-operation function. |
@@ -128,7 +128,7 @@ Some caveats and gotchas while using `react-native-sliding-drawer`
128
128
129
129
`<SlidingDrawer></SlidingDrawer>` is sensitive to position. Its own position prop is set to "absolute", but if some of its parent components have restricting positioning or sizing, the rendered sliding drawer might have unexpected height, width, peek size, etc. It is thus highly recommended that `<SlidingDrawer></SlidingDrawer>` has as few parents as possible (i.e. it is coded as close to top level component as possible). This way, there is less risk of the sliding drawer being constraint by some other components. If, however, the sliding drawer must be deeply nested, make sure that each of its parent has loose positioning or sizing.
130
130
131
-
For instance, the minimal workable example is a valid way use `<SlidingDrawer></SlidingDrawer>`, because its parent spreads the entire screen. However, if we put a restricting style on the parent such as the one shown below
131
+
For instance, the minimal workable example is a valid way to use `<SlidingDrawer></SlidingDrawer>`, because its parent spreads the entire screen. However, if we put a restricting style on the parent such as the one shown below
The sliding drawer no longer behaves as expected (it doesn't cover the entire width of the screen)
169
169
170
170

171
171
@@ -185,7 +185,7 @@ const App = () => {
185
185
justifyContent:'center',
186
186
alignItems:'center',
187
187
backgroundColor:'yellow',
188
-
width:100,
188
+
width:100,// restricting style
189
189
}}>
190
190
<Text>Minimal Example</Text>
191
191
</View>
@@ -204,7 +204,7 @@ const App = () => {
204
204
};
205
205
```
206
206
207
-
Now the sliding drawer behavior is normal
207
+
Now the sliding drawer behavior is normal (drawer covers the entire width of the screen)
208
208
209
209

210
210
@@ -284,12 +284,12 @@ export default App;
284
284
285
285

286
286
287
-
The desired behavior is that each time the drawer opens or closes, the counter counts up. We can see that the desired behavior is achieved using the non-slide open feature. However, when the drawer slides open or close, the counter gets stuck at 1. This is `onDrawerOpen` and `onDrawerPeek` are cached in a ref (hence, the value in `count` is forever the initialized value, which is 0) when the drawer is opened or closed via sliding. Any further change to `count` does not alter its cached value inside the ref. On the other hand, the two callbacks are NOT cached when the drawer is opened or closed via the non-slide open feature. Hence, the value in `count` does change.
287
+
The desired behavior is that each time the drawer opens or closes, the counter counts up. We can see that the desired behavior is achieved using the non-slide open feature. However, when the drawer slides open or close, the counter gets stuck at 1. This is because `onDrawerOpen` and `onDrawerPeek` are cached in a ref when the drawer is opened or closed via sliding. Hence, the value in `count` is forever the initialized value, which is 0. Any further change to `count` does not alter its cached value inside the ref. On the other hand, if the drawer is opened or closed via the non-slide open feature, the callbacks are NOT cached; thus, their value in `count` does change.
288
288
289
289
There are two ways to work around this limtation.
290
290
291
291
1. If the values in the callback can be hard coded, do it! For instance, instead of using `setIsInitialPeek(!isInitialPeek)` for both `onDrawerOpen` and `onDrawerPeek`, hard code the true and false value.
292
-
2. If including dynamic variables is inevitable for the two callbacks, consider disabling the slide open feature. This can be achieved by setting the prop `enableSlideOpen` to false.
292
+
2. If including dynamic variables is inevitable for the two callbacks, consider disabling the slide open feature. In other words, force the user to open the drawer via the non-slide open feature, such that the callback is always executed as desired. This can be achieved by setting the prop `enableSlideOpen` to false.
293
293
294
294
Of course, if anyone has a solution to directly resolve this issue, please share your thoughts and open a pull request.
0 commit comments