-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRightDrawer.tsx
71 lines (68 loc) · 2.31 KB
/
RightDrawer.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* Generated with the TypeScript template
* https://github.com/react-native-community/react-native-template-typescript
*
* @format
*/
import * as React from 'react';
import {SlidingDrawer} from '../../react-native-sliding-drawer';
import {ScrollableRightDrawerContent} from '../Content/right';
/**
* Example for a right drawer
*/
export const RightDrawer: React.FC = () => {
const peekSize = 95;
const openSize = 300;
const scrollWidth = 300;
const scrollHeight = 150;
// scrollPageX is the distance from left of the screen to the left of the
// scroll view
const [scrollPageX, setScrollPageX] = React.useState<number>(-1);
// scrollPageY is the distance from top of the screen to the top of the
// scroll view
const [scrollPageY, setScrollPageY] = React.useState<number>(-1);
// Double rendering, a common trick to pre-render a fake sliding drawer to
// measure the positioning of the desired components and then render the real
// sliding drawer with the pre-measured positions. This is a necessary trick
// because the real sliding drawer does not respond to re-rendering
// (animation is done based on refs, so the initial value stays forever).
// Hence, one cannot dynamically make changes to the positioning within the
// sliding drawer.
return scrollPageX < 0 || scrollPageY < 0 ? (
<SlidingDrawer
peekSize={peekSize}
openSize={openSize}
fixedLoc="right"
isInitialPeek={false}
maxPct={0.9}
expandable={false}>
<ScrollableRightDrawerContent
peekSize={peekSize}
scrollWidth={scrollWidth}
scrollHeight={scrollHeight}
setScrollPageX={setScrollPageX}
setScrollPageY={setScrollPageY}
/>
</SlidingDrawer>
) : (
<SlidingDrawer
peekSize={peekSize}
openSize={openSize}
fixedLoc="right"
isInitialPeek={false}
maxPct={0.9}
nonSlideableXRanges={[[scrollPageX, scrollPageX + scrollHeight]]}
nonSlideableYRanges={[[scrollPageY, scrollPageY + scrollWidth]]}>
<ScrollableRightDrawerContent
peekSize={peekSize}
scrollWidth={scrollWidth}
scrollHeight={scrollHeight}
setScrollPageX={setScrollPageX}
setScrollPageY={setScrollPageY}
/>
</SlidingDrawer>
);
};