expo-stacked-sheets 0.0.0-stage → 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015-present 650 Industries, Inc. (aka Expo)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,55 @@
1
- # Temporary Holding Version
1
+ # Expo Stacked Sheets
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Edit multiple drafts in an Expo app. Minimize them to keep using the current
4
+ screen, then reopen any draft from an iOS Mail-style card overview.
5
+
6
+ ## Install
7
+
8
+ Requires Expo SDK 58 and React Native 0.88.
9
+
10
+ ```sh
11
+ npx expo install expo-stacked-sheets
12
+ ```
13
+
14
+ If your SDK patch uses Safe Area Context 5.10.x (such as Expo 58.0.22), include
15
+ `'react-native-safe-area-context@~5.10.1'` in the install command.
16
+
17
+ ## Usage
18
+
19
+ ```tsx
20
+ import { StackedSheets } from 'expo-stacked-sheets';
21
+ import { Button } from 'react-native';
22
+ import { GestureHandlerRootView } from 'react-native-gesture-handler';
23
+ import { SafeAreaProvider, SafeAreaView } from 'react-native-safe-area-context';
24
+
25
+ export default function App() {
26
+ return (
27
+ <GestureHandlerRootView style={{ flex: 1 }}>
28
+ <SafeAreaProvider>
29
+ <StackedSheets
30
+ renderBackground={({ active, openSheet }) => (
31
+ <SafeAreaView>
32
+ <Button title="New draft" disabled={!active} onPress={() => openSheet()} />
33
+ </SafeAreaView>
34
+ )}
35
+ />
36
+ </SafeAreaProvider>
37
+ </GestureHandlerRootView>
38
+ );
39
+ }
40
+ ```
41
+
42
+ Reuse the providers if your app already has them. Drafts stay in memory.
43
+ Use `onSaveSheet` to save them in your app.
44
+ [Component props](https://github.com/Fizzbow/expo-stacked-sheets/blob/main/packages/stacked-sheets/src/types.ts)
45
+
46
+ ## Run the Notes demo
47
+
48
+ From a [repository checkout](https://github.com/Fizzbow/expo-stacked-sheets), run
49
+ `npm ci && npm start`. Press `i` for iOS or `a` for Android.
50
+ [Photo credits](https://github.com/Fizzbow/expo-stacked-sheets/blob/main/assets/notes/CREDITS.md)
51
+
52
+ For an unpublished build, run `npm pack --workspace expo-stacked-sheets` and
53
+ install the resulting `.tgz` in your Expo app.
54
+
55
+ [MIT](https://github.com/Fizzbow/expo-stacked-sheets/blob/main/LICENSE)
package/package.json CHANGED
@@ -1,6 +1,39 @@
1
1
  {
2
2
  "name": "expo-stacked-sheets",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Stacked sheet editing and overview for Expo and React Native",
5
+ "keywords": ["expo", "react-native", "stacked-sheets", "drafts", "reanimated"],
6
+ "license": "MIT",
7
+ "homepage": "https://github.com/Fizzbow/expo-stacked-sheets",
8
+ "bugs": "https://github.com/Fizzbow/expo-stacked-sheets/issues",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/Fizzbow/expo-stacked-sheets.git",
12
+ "directory": "packages/stacked-sheets"
13
+ },
14
+ "main": "./src/index.ts",
15
+ "react-native": "./src/index.ts",
16
+ "types": "./src/index.ts",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./src/index.ts",
20
+ "react-native": "./src/index.ts",
21
+ "default": "./src/index.ts"
22
+ }
23
+ },
24
+ "files": ["src"],
25
+ "scripts": {
26
+ "prepack": "node -e \"require('node:fs').copyFileSync('../../README.md', 'README.md')\""
27
+ },
28
+ "peerDependencies": {
29
+ "@react-navigation/native": "^7.5.1",
30
+ "@react-navigation/native-stack": "^7.21.0",
31
+ "react": "^19.3.0",
32
+ "react-native": "~0.88.0",
33
+ "react-native-gesture-handler": "~3.3.0",
34
+ "react-native-reanimated": "4.7.1",
35
+ "react-native-safe-area-context": "~5.10.1 || ~5.11.1",
36
+ "react-native-screens": "~4.30.1",
37
+ "react-native-worklets": "0.13.0"
38
+ }
39
+ }
@@ -0,0 +1,346 @@
1
+ import { useCallback, useEffect, useRef, useState, type ComponentRef } from 'react';
2
+ import {
3
+ Image,
4
+ Keyboard,
5
+ KeyboardAvoidingView,
6
+ Platform,
7
+ Pressable,
8
+ ScrollView,
9
+ StyleSheet,
10
+ Text,
11
+ TextInput,
12
+ View,
13
+ useWindowDimensions,
14
+ } from 'react-native';
15
+ import { GestureDetector, usePanGesture } from 'react-native-gesture-handler';
16
+ import Animated, {
17
+ cancelAnimation,
18
+ useAnimatedReaction,
19
+ useAnimatedStyle,
20
+ useSharedValue,
21
+ withSpring,
22
+ } from 'react-native-reanimated';
23
+ import { useSafeAreaInsets } from 'react-native-safe-area-context';
24
+ import { scheduleOnRN } from 'react-native-worklets';
25
+ import {
26
+ SPRING,
27
+ clamp,
28
+ mixEditorFrames,
29
+ paperTransforms,
30
+ shouldMinimize,
31
+ } from './sheetLayout';
32
+ import { useDraft, useMailView, useMotion, useSheetController } from './sheetMotion';
33
+ import { SheetControlIcon } from './StackedCard';
34
+ import type { SheetContent, StackedSheetsProps } from './types';
35
+
36
+ const android = Platform.OS === 'android';
37
+
38
+ function dismissKeyboard() {
39
+ Keyboard.dismiss();
40
+ }
41
+
42
+ /** One editor shell is reused across sheets. Other sheets render lightweight previews. */
43
+ export function SheetEditor({
44
+ id,
45
+ emptyTitle,
46
+ renderEditor,
47
+ onSaveSheet,
48
+ renderIcon,
49
+ }: {
50
+ id: string | null;
51
+ emptyTitle: string;
52
+ } & Pick<StackedSheetsProps, 'renderEditor' | 'renderIcon' | 'onSaveSheet'>) {
53
+ const sheet = useDraft(id ?? '');
54
+ const { closeDraft, isEditing, minimizeCompose, requestCloseTop, store } = useSheetController();
55
+ const { mode } = useMailView();
56
+ const { editor, frame, dock, full } = useMotion();
57
+ const { height, width } = useWindowDimensions();
58
+ const insets = useSafeAreaInsets();
59
+ const top = insets.top + 4;
60
+ const titleRef = useRef<ComponentRef<typeof TextInput>>(null);
61
+ const dragStart = useSharedValue(full);
62
+ const [readyId, setReadyId] = useState<string | null>(null);
63
+ const [saveErrorId, setSaveErrorId] = useState<string | null>(null);
64
+ const customEditor = !!renderEditor;
65
+ const onReady = (nextId: string | null) => {
66
+ if (!nextId || !isEditing(nextId)) {
67
+ setReadyId(null);
68
+ return;
69
+ }
70
+ if (customEditor) {
71
+ setReadyId(nextId);
72
+ return;
73
+ }
74
+ // Existing content opens for reading. Focus the title on blank sheets.
75
+ const current = store.getDraft(nextId);
76
+ if (current && !current.title && !current.body && !current.image)
77
+ titleRef.current?.focus();
78
+ };
79
+ useAnimatedReaction(
80
+ () => mode === 'compose' && editor.value >= 0.98 ? id : null,
81
+ (nextId, previousId) => {
82
+ if (nextId !== previousId) scheduleOnRN(onReady, nextId);
83
+ },
84
+ );
85
+ const update = useCallback((changes: Partial<SheetContent>) => {
86
+ if (id) store.updateDraft(id, changes);
87
+ }, [id, store]);
88
+ useEffect(() => {
89
+ if (mode !== 'compose') return;
90
+ frame.set(withSpring(full, SPRING));
91
+ }, [mode, id, frame, full]);
92
+ const pan = usePanGesture({
93
+ enabled: mode === 'compose',
94
+ activeOffsetY: 8,
95
+ failOffsetX: [-24, 24],
96
+ onActivate: () => {
97
+ 'worklet';
98
+ cancelAnimation(frame);
99
+ dragStart.value = frame.value;
100
+ scheduleOnRN(dismissKeyboard);
101
+ },
102
+ onUpdate: (event) => {
103
+ 'worklet';
104
+ const distance = Math.max(1, dock.top - dragStart.value.top);
105
+ frame.set(mixEditorFrames(dragStart.value, dock, event.translationY / distance));
106
+ },
107
+ onDeactivate: (event) => {
108
+ 'worklet';
109
+ if (shouldMinimize(event.translationY, event.velocityY ?? 0, !!event.canceled))
110
+ scheduleOnRN(minimizeCompose);
111
+ else frame.set(withSpring(full, SPRING));
112
+ },
113
+ });
114
+ const style = useAnimatedStyle(() => {
115
+ const f = frame.value;
116
+ return {
117
+ left: (width - f.width) / 2,
118
+ width: f.width,
119
+ height: f.height,
120
+ borderRadius: f.radius,
121
+ opacity: f.progress <= 0 ? 0 : 1,
122
+ transform: paperTransforms(android, f.top, f.cosine, f.taper),
123
+ };
124
+ });
125
+ // Content keeps its full-screen layout; the paper frame clips it while it morphs.
126
+ const contentStyle = useAnimatedStyle(() => ({
127
+ left: (frame.value.width - width) / 2,
128
+ opacity: clamp((frame.value.progress - 0.22) / 0.56, 0, 1),
129
+ }));
130
+ const compactStyle = useAnimatedStyle(() => ({
131
+ opacity: frame.value.compact * clamp((0.28 - frame.value.progress) / 0.28, 0, 1),
132
+ }));
133
+ const title = sheet?.title ?? '';
134
+ const image = sheet?.image;
135
+ const canSave = Boolean(title.trim() || sheet?.body.trim() || image);
136
+
137
+ const saveSheet = () => {
138
+ if (!id || !isEditing(id) || !onSaveSheet) return;
139
+ const current = store.getDraft(id);
140
+ if (!current || !(current.title.trim() || current.body.trim() || current.image)) return;
141
+ try {
142
+ if (!onSaveSheet(current)) {
143
+ setSaveErrorId(id);
144
+ return;
145
+ }
146
+ } catch {
147
+ setSaveErrorId(id);
148
+ return;
149
+ }
150
+ setSaveErrorId(null);
151
+ closeDraft(id);
152
+ };
153
+
154
+ return (
155
+ <Animated.View
156
+ testID="compose-editor"
157
+ pointerEvents={mode === 'compose' ? 'auto' : 'none'}
158
+ aria-hidden={mode !== 'compose'}
159
+ accessibilityElementsHidden={mode !== 'compose'}
160
+ importantForAccessibility={mode === 'compose' ? 'auto' : 'no-hide-descendants'}
161
+ style={[styles.root, style]}
162
+ >
163
+ <Animated.View
164
+ style={[styles.editorContent, { width, height: height - top }, contentStyle]}
165
+ >
166
+ <KeyboardAvoidingView
167
+ style={styles.flex}
168
+ behavior={Platform.OS === 'ios' ? 'padding' : undefined}
169
+ >
170
+ <GestureDetector gesture={pan}>
171
+ <View style={styles.header}>
172
+ <View style={styles.handleButton}>
173
+ <View style={styles.handle} />
174
+ </View>
175
+ <View style={styles.toolbar}>
176
+ <Pressable
177
+ accessibilityRole="button"
178
+ accessibilityLabel="Minimize sheet"
179
+ testID="compose-minimize"
180
+ hitSlop={10}
181
+ onPress={(event) => {
182
+ if (Platform.OS === 'web')
183
+ (event.currentTarget as unknown as { blur?: () => void }).blur?.();
184
+ minimizeCompose();
185
+ }}
186
+ style={({ pressed }) => [styles.icon, pressed && styles.pressed]}
187
+ >
188
+ <SheetControlIcon name="minimize" size={22} renderIcon={renderIcon} />
189
+ </Pressable>
190
+ <View style={styles.toolbarActions}>
191
+ {onSaveSheet && (
192
+ <Pressable
193
+ accessibilityRole="button"
194
+ accessibilityLabel="Save note"
195
+ testID="compose-save"
196
+ disabled={!canSave}
197
+ onPress={saveSheet}
198
+ style={({ pressed }) => [styles.saveButton, pressed && styles.pressed]}
199
+ >
200
+ <Text style={[styles.saveLabel, !canSave && styles.saveDisabled]}>Save</Text>
201
+ </Pressable>
202
+ )}
203
+ <Pressable
204
+ accessibilityRole="button"
205
+ accessibilityLabel="Close sheet"
206
+ testID="compose-close"
207
+ hitSlop={10}
208
+ onPress={requestCloseTop}
209
+ style={({ pressed }) => [styles.icon, pressed && styles.pressed]}
210
+ >
211
+ <SheetControlIcon name="close" size={22} renderIcon={renderIcon} />
212
+ </Pressable>
213
+ </View>
214
+ </View>
215
+ {saveErrorId && saveErrorId === id && (
216
+ <Text accessibilityRole="alert" style={styles.saveError}>Couldn’t save the note. Try again.</Text>
217
+ )}
218
+ </View>
219
+ </GestureDetector>
220
+ {renderEditor ? (
221
+ sheet && (
222
+ <View key={sheet.id} style={styles.flex}>
223
+ {renderEditor({ sheet, update, ready: mode === 'compose' && readyId === id })}
224
+ </View>
225
+ )
226
+ ) : (
227
+ <ScrollView
228
+ keyboardShouldPersistTaps="handled"
229
+ keyboardDismissMode="interactive"
230
+ contentContainerStyle={styles.content}
231
+ >
232
+ <TextInput
233
+ ref={titleRef}
234
+ accessibilityLabel="Title"
235
+ placeholder="Title"
236
+ placeholderTextColor={MUTED}
237
+ value={title}
238
+ onChangeText={(nextTitle) => update({ title: nextTitle })}
239
+ style={styles.title}
240
+ multiline
241
+ submitBehavior="blurAndSubmit"
242
+ />
243
+ {image && (
244
+ <View style={styles.photoFrame}>
245
+ <Image
246
+ source={image.source}
247
+ accessible
248
+ accessibilityLabel={image.label}
249
+ style={styles.photo}
250
+ resizeMode="cover"
251
+ />
252
+ </View>
253
+ )}
254
+ <TextInput
255
+ accessibilityLabel="Body"
256
+ placeholder="Start writing…"
257
+ placeholderTextColor={MUTED}
258
+ value={sheet?.body ?? ''}
259
+ onChangeText={(body) => update({ body })}
260
+ multiline
261
+ style={styles.body}
262
+ textAlignVertical="top"
263
+ />
264
+ </ScrollView>
265
+ )}
266
+ </KeyboardAvoidingView>
267
+ </Animated.View>
268
+ <Animated.View
269
+ pointerEvents="none"
270
+ aria-hidden
271
+ accessibilityElementsHidden
272
+ style={[styles.compact, compactStyle]}
273
+ >
274
+ <Text numberOfLines={1} style={styles.compactTitle}>
275
+ {title || emptyTitle}
276
+ </Text>
277
+ </Animated.View>
278
+ </Animated.View>
279
+ );
280
+ }
281
+
282
+ const INK = '#111';
283
+ const MUTED = '#B0B0B5';
284
+
285
+ const styles = StyleSheet.create({
286
+ root: {
287
+ position: 'absolute',
288
+ top: 0,
289
+ backgroundColor: '#FFF',
290
+ overflow: 'hidden',
291
+ transformOrigin: '50% 0%',
292
+ borderWidth: StyleSheet.hairlineWidth,
293
+ borderColor: 'rgba(0,0,0,0.08)',
294
+ },
295
+ editorContent: { position: 'absolute', top: 0 },
296
+ flex: { flex: 1 },
297
+ compact: { ...StyleSheet.absoluteFill, alignItems: 'center', justifyContent: 'center' },
298
+ compactTitle: { fontSize: 16, fontWeight: '600', color: INK, paddingHorizontal: 24 },
299
+ header: { paddingBottom: 4 },
300
+ handleButton: { height: 20, alignItems: 'center', justifyContent: 'center' },
301
+ handle: { width: 36, height: 5, borderRadius: 3, backgroundColor: '#E0E0E0' },
302
+ toolbar: {
303
+ flexDirection: 'row',
304
+ alignItems: 'center',
305
+ justifyContent: 'space-between',
306
+ paddingHorizontal: 12,
307
+ },
308
+ toolbarActions: { flexDirection: 'row', alignItems: 'center', gap: 4 },
309
+ saveButton: { minHeight: 44, paddingHorizontal: 12, justifyContent: 'center', borderRadius: 22 },
310
+ saveLabel: { color: INK, fontSize: 16, fontWeight: '600' },
311
+ saveDisabled: { color: MUTED },
312
+ saveError: { color: '#A62828', paddingHorizontal: 24, paddingTop: 4 },
313
+ icon: {
314
+ width: 40,
315
+ height: 40,
316
+ borderRadius: 20,
317
+ alignItems: 'center',
318
+ justifyContent: 'center',
319
+ },
320
+ pressed: { backgroundColor: '#F2F2F2' },
321
+ content: { paddingHorizontal: 24, paddingTop: 12, paddingBottom: 60 },
322
+ title: {
323
+ fontSize: 28,
324
+ lineHeight: 34,
325
+ fontWeight: '700',
326
+ letterSpacing: -0.4,
327
+ color: INK,
328
+ padding: 0,
329
+ },
330
+ photoFrame: {
331
+ width: '100%',
332
+ aspectRatio: 3 / 2,
333
+ borderRadius: 12,
334
+ marginTop: 16,
335
+ overflow: 'hidden',
336
+ },
337
+ photo: { width: '100%', height: '100%' },
338
+ body: {
339
+ marginTop: 16,
340
+ minHeight: 200,
341
+ fontSize: 17,
342
+ lineHeight: 27,
343
+ color: '#333',
344
+ padding: 0,
345
+ },
346
+ });