@punks/cli 2.3.2 → 2.4.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/dist/BASELINE_CHANGELOG.md +50 -0
- package/dist/CHANGELOG.md +50 -0
- package/dist/index.js +216 -221
- package/dist/skills/agnostic/cli/dp-cli/SKILL.md +1 -12
- package/dist/skills/agnostic/cli/dp-cli/references/commands.md +22 -18
- package/dist/skills/agnostic/cli/dp-cli/references/post-command-flow.md +15 -19
- package/dist/skills/agnostic/planning/wayfinder/SKILL.md +42 -0
- package/dist/skills/agnostic/quality/review/SKILL.md +89 -0
- package/dist/skills/agnostic/requirements/write-backlog/EXAMPLES.md +22 -0
- package/dist/skills/agnostic/requirements/write-backlog/REFERENCE.md +110 -23
- package/dist/skills/agnostic/requirements/write-backlog/SKILL.md +30 -14
- package/dist/skills/agnostic/requirements/write-backlog/assets/concepts/backlog-model.md +74 -7
- package/dist/skills/agnostic/requirements/write-backlog/assets/concepts/story-shape.md +108 -2
- package/dist/skills/agnostic/requirements/write-backlog/assets/providers/azure-devops-create-payload.md +29 -3
- package/dist/skills/agnostic/requirements/write-backlog/assets/providers/github-projects-create-payload.md +43 -7
- package/dist/skills/agnostic/requirements/write-backlog/assets/providers/linear-create-payload.md +25 -3
- package/dist/skills/agnostic/requirements/write-backlog/assets/providers/monday-create-payload.md +63 -14
- package/dist/skills/agnostic/research/parallel-research/SKILL.md +5 -2
- package/dist/skills/frameworks/expo/add-app-clip/SKILL.md +280 -0
- package/dist/skills/frameworks/expo/add-app-clip/agents/openai.yaml +4 -0
- package/dist/skills/frameworks/expo/add-app-clip/references/native-module.md +96 -0
- package/dist/skills/frameworks/expo/building-native-ui/SKILL.md +377 -0
- package/dist/skills/frameworks/expo/building-native-ui/agents/openai.yaml +4 -0
- package/dist/skills/frameworks/expo/building-native-ui/references/animations.md +220 -0
- package/dist/skills/frameworks/expo/building-native-ui/references/controls.md +270 -0
- package/dist/skills/frameworks/expo/building-native-ui/references/form-sheet.md +253 -0
- package/dist/skills/frameworks/expo/building-native-ui/references/gradients.md +106 -0
- package/dist/skills/frameworks/expo/building-native-ui/references/icons.md +213 -0
- package/dist/skills/frameworks/expo/building-native-ui/references/media.md +198 -0
- package/dist/skills/frameworks/expo/building-native-ui/references/route-structure.md +229 -0
- package/dist/skills/frameworks/expo/building-native-ui/references/search.md +248 -0
- package/dist/skills/frameworks/expo/building-native-ui/references/storage.md +121 -0
- package/dist/skills/frameworks/expo/building-native-ui/references/tabs.md +433 -0
- package/dist/skills/frameworks/expo/building-native-ui/references/toolbar-and-headers.md +284 -0
- package/dist/skills/frameworks/expo/building-native-ui/references/visual-effects.md +197 -0
- package/dist/skills/frameworks/expo/building-native-ui/references/webgpu-three.md +605 -0
- package/dist/skills/frameworks/expo/building-native-ui/references/zoom-transitions.md +158 -0
- package/dist/skills/frameworks/expo/eas-simulator/SKILL.md +154 -0
- package/dist/skills/frameworks/expo/eas-simulator/references/controllers.md +67 -0
- package/dist/skills/frameworks/expo/eas-simulator/references/run-your-app.md +185 -0
- package/dist/skills/frameworks/expo/eas-simulator/references/troubleshooting.md +38 -0
- package/dist/skills/frameworks/expo/eas-update-insights/SKILL.md +228 -0
- package/dist/skills/frameworks/expo/eas-update-insights/agents/openai.yaml +4 -0
- package/dist/skills/frameworks/expo/eas-update-insights/references/channel-insights-schema.md +47 -0
- package/dist/skills/frameworks/expo/eas-update-insights/references/update-insights-schema.md +69 -0
- package/dist/skills/frameworks/expo/expo-api-routes/SKILL.md +368 -0
- package/dist/skills/frameworks/expo/expo-api-routes/agents/openai.yaml +4 -0
- package/dist/skills/frameworks/expo/expo-brownfield/SKILL.md +54 -0
- package/dist/skills/frameworks/expo/expo-brownfield/agents/openai.yaml +4 -0
- package/dist/skills/frameworks/expo/expo-brownfield/references/brownfield-integrated.md +526 -0
- package/dist/skills/frameworks/expo/expo-brownfield/references/brownfield-isolated.md +402 -0
- package/dist/skills/frameworks/expo/expo-brownfield/references/comparison.md +63 -0
- package/dist/skills/frameworks/expo/expo-brownfield/references/troubleshooting.md +88 -0
- package/dist/skills/frameworks/expo/expo-cicd-workflows/SKILL.md +92 -0
- package/dist/skills/frameworks/expo/expo-cicd-workflows/agents/openai.yaml +4 -0
- package/dist/skills/frameworks/expo/expo-cicd-workflows/scripts/fetch.js +109 -0
- package/dist/skills/frameworks/expo/expo-cicd-workflows/scripts/package.json +11 -0
- package/dist/skills/frameworks/expo/expo-cicd-workflows/scripts/validate.js +84 -0
- package/dist/skills/frameworks/expo/expo-deployment/SKILL.md +167 -0
- package/dist/skills/frameworks/expo/expo-deployment/agents/openai.yaml +4 -0
- package/dist/skills/frameworks/expo/expo-deployment/references/app-store-metadata.md +497 -0
- package/dist/skills/frameworks/expo/expo-deployment/references/ios-app-store.md +371 -0
- package/dist/skills/frameworks/expo/expo-deployment/references/play-store.md +246 -0
- package/dist/skills/frameworks/expo/expo-deployment/references/testflight.md +58 -0
- package/dist/skills/frameworks/expo/expo-deployment/references/workflows.md +160 -0
- package/dist/skills/frameworks/expo/expo-dev-client/SKILL.md +172 -0
- package/dist/skills/frameworks/expo/expo-dev-client/agents/openai.yaml +4 -0
- package/dist/skills/frameworks/expo/expo-examples/SKILL.md +97 -0
- package/dist/skills/frameworks/expo/expo-examples/references/catalog.md +105 -0
- package/dist/skills/frameworks/expo/expo-module/SKILL.md +141 -0
- package/dist/skills/frameworks/expo/expo-module/agents/openai.yaml +4 -0
- package/dist/skills/frameworks/expo/expo-module/references/config-plugin.md +90 -0
- package/dist/skills/frameworks/expo/expo-module/references/create-expo-module.md +206 -0
- package/dist/skills/frameworks/expo/expo-module/references/lifecycle.md +127 -0
- package/dist/skills/frameworks/expo/expo-module/references/module-config.md +48 -0
- package/dist/skills/frameworks/expo/expo-module/references/native-module.md +286 -0
- package/dist/skills/frameworks/expo/expo-module/references/native-view.md +171 -0
- package/dist/skills/frameworks/expo/expo-observe/SKILL.md +29 -0
- package/dist/skills/frameworks/expo/expo-observe/references/metrics.md +47 -0
- package/dist/skills/frameworks/expo/expo-observe/references/queries.md +342 -0
- package/dist/skills/frameworks/expo/expo-observe/references/setup.md +255 -0
- package/dist/skills/frameworks/expo/expo-skill-eval/SKILL.md +314 -0
- package/dist/skills/frameworks/expo/expo-skill-eval/agents/visual-grader.md +52 -0
- package/dist/skills/frameworks/expo/expo-skill-eval/references/design-rubric.md +45 -0
- package/dist/skills/frameworks/expo/expo-skill-eval/references/runtime-matrix.md +33 -0
- package/dist/skills/frameworks/expo/expo-skill-eval/scripts/check-static.sh +64 -0
- package/dist/skills/frameworks/expo/expo-skill-eval/scripts/clean-fixture.sh +56 -0
- package/dist/skills/frameworks/expo/expo-skill-eval/scripts/generate_viewer.py +450 -0
- package/dist/skills/frameworks/expo/expo-skill-eval/scripts/latest-sdk.sh +46 -0
- package/dist/skills/frameworks/expo/expo-skill-eval/scripts/make-fixture.sh +95 -0
- package/dist/skills/frameworks/expo/expo-skill-eval/scripts/make-workspace.sh +31 -0
- package/dist/skills/frameworks/expo/expo-skill-eval/scripts/snapshot-android.sh +284 -0
- package/dist/skills/frameworks/expo/expo-skill-eval/scripts/snapshot-ios.sh +132 -0
- package/dist/skills/frameworks/expo/expo-skill-eval/scripts/snapshot-web.sh +61 -0
- package/dist/skills/frameworks/expo/expo-tailwind-setup/SKILL.md +480 -0
- package/dist/skills/frameworks/expo/expo-tailwind-setup/agents/openai.yaml +4 -0
- package/dist/skills/frameworks/expo/expo-ui/SKILL.md +47 -0
- package/dist/skills/frameworks/expo/expo-ui/agents/openai.yaml +4 -0
- package/dist/skills/frameworks/expo/expo-ui/references/drop-in-replacements.md +27 -0
- package/dist/skills/frameworks/expo/expo-ui/references/jetpack-compose.md +73 -0
- package/dist/skills/frameworks/expo/expo-ui/references/swift-ui.md +73 -0
- package/dist/skills/frameworks/expo/expo-ui/references/universal.md +73 -0
- package/dist/skills/frameworks/expo/expo-ui/scripts/list-components.js +193 -0
- package/dist/skills/frameworks/expo/native-data-fetching/SKILL.md +505 -0
- package/dist/skills/frameworks/expo/native-data-fetching/agents/openai.yaml +4 -0
- package/dist/skills/frameworks/expo/native-data-fetching/references/expo-router-loaders.md +341 -0
- package/dist/skills/frameworks/expo/upgrading-expo/SKILL.md +134 -0
- package/dist/skills/frameworks/expo/upgrading-expo/agents/openai.yaml +4 -0
- package/dist/skills/frameworks/expo/upgrading-expo/references/expo-av-to-audio.md +132 -0
- package/dist/skills/frameworks/expo/upgrading-expo/references/expo-av-to-video.md +160 -0
- package/dist/skills/frameworks/expo/upgrading-expo/references/native-tabs.md +124 -0
- package/dist/skills/frameworks/expo/upgrading-expo/references/new-architecture.md +79 -0
- package/dist/skills/frameworks/expo/upgrading-expo/references/react-19.md +79 -0
- package/dist/skills/frameworks/expo/upgrading-expo/references/react-compiler.md +59 -0
- package/dist/skills/frameworks/expo/upgrading-expo/references/react-navigation-to-expo-router.md +61 -0
- package/dist/skills/frameworks/expo/use-dom/SKILL.md +417 -0
- package/dist/skills/frameworks/expo/use-dom/agents/openai.yaml +4 -0
- package/dist/skills/frameworks/expo/web-to-native/SKILL.md +83 -0
- package/dist/skills/frameworks/expo/web-to-native/references/false-friends.md +119 -0
- package/dist/skills/frameworks/expo/web-to-native/references/native-patterns.md +39 -0
- package/dist/skills/frameworks/expo/web-to-native/references/run-as-goal.md +48 -0
- package/dist/skills/frameworks/expo/web-to-native/references/verify-on-device.md +45 -0
- package/dist/skills/phases/finder-phase/SKILL.md +52 -0
- package/dist/skills/phases/finder-phase/references/frontier-lifecycle.md +70 -0
- package/dist/skills/phases/finder-phase/references/root-routing.md +29 -0
- package/dist/skills/phases/goalify/SKILL.md +10 -7
- package/dist/skills/phases/review-phase/REFERENCE.md +36 -3
- package/dist/skills/phases/review-phase/SKILL.md +18 -11
- package/package.json +1 -1
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
# Search
|
|
2
|
+
|
|
3
|
+
## Header Search Bar
|
|
4
|
+
|
|
5
|
+
Add a search bar to the stack header with `headerSearchBarOptions`:
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
<Stack.Screen
|
|
9
|
+
name="index"
|
|
10
|
+
options={{
|
|
11
|
+
headerSearchBarOptions: {
|
|
12
|
+
placeholder: "Search",
|
|
13
|
+
onChangeText: (event) => console.log(event.nativeEvent.text),
|
|
14
|
+
},
|
|
15
|
+
}}
|
|
16
|
+
/>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Options
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
headerSearchBarOptions: {
|
|
23
|
+
// Placeholder text
|
|
24
|
+
placeholder: "Search items...",
|
|
25
|
+
|
|
26
|
+
// Auto-capitalize behavior
|
|
27
|
+
autoCapitalize: "none",
|
|
28
|
+
|
|
29
|
+
// Input type
|
|
30
|
+
inputType: "text", // "text" | "phone" | "number" | "email"
|
|
31
|
+
|
|
32
|
+
// Cancel button text (iOS)
|
|
33
|
+
cancelButtonText: "Cancel",
|
|
34
|
+
|
|
35
|
+
// Hide when scrolling (iOS)
|
|
36
|
+
hideWhenScrolling: true,
|
|
37
|
+
|
|
38
|
+
// Hide navigation bar during search (iOS)
|
|
39
|
+
hideNavigationBar: true,
|
|
40
|
+
|
|
41
|
+
// Obscure background during search (iOS)
|
|
42
|
+
obscureBackground: true,
|
|
43
|
+
|
|
44
|
+
// Placement
|
|
45
|
+
placement: "automatic", // "automatic" | "inline" | "stacked"
|
|
46
|
+
|
|
47
|
+
// Callbacks
|
|
48
|
+
onChangeText: (event) => {},
|
|
49
|
+
onSearchButtonPress: (event) => {},
|
|
50
|
+
onCancelButtonPress: (event) => {},
|
|
51
|
+
onFocus: () => {},
|
|
52
|
+
onBlur: () => {},
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## useSearch Hook
|
|
57
|
+
|
|
58
|
+
Reusable hook for search state management:
|
|
59
|
+
|
|
60
|
+
```tsx
|
|
61
|
+
import { useEffect, useState } from "react";
|
|
62
|
+
import { useNavigation } from "expo-router";
|
|
63
|
+
|
|
64
|
+
export function useSearch(options: any = {}) {
|
|
65
|
+
const [search, setSearch] = useState("");
|
|
66
|
+
const navigation = useNavigation();
|
|
67
|
+
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
navigation.setOptions({
|
|
70
|
+
headerShown: true,
|
|
71
|
+
headerSearchBarOptions: {
|
|
72
|
+
...options,
|
|
73
|
+
onChangeText(e: any) {
|
|
74
|
+
setSearch(e.nativeEvent.text);
|
|
75
|
+
options.onChangeText?.(e);
|
|
76
|
+
},
|
|
77
|
+
onSearchButtonPress(e: any) {
|
|
78
|
+
setSearch(e.nativeEvent.text);
|
|
79
|
+
options.onSearchButtonPress?.(e);
|
|
80
|
+
},
|
|
81
|
+
onCancelButtonPress(e: any) {
|
|
82
|
+
setSearch("");
|
|
83
|
+
options.onCancelButtonPress?.(e);
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}, [options, navigation]);
|
|
88
|
+
|
|
89
|
+
return search;
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Usage
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
function SearchScreen() {
|
|
97
|
+
const search = useSearch({ placeholder: "Search items..." });
|
|
98
|
+
|
|
99
|
+
const filteredItems = items.filter(item =>
|
|
100
|
+
item.name.toLowerCase().includes(search.toLowerCase())
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<FlatList
|
|
105
|
+
data={filteredItems}
|
|
106
|
+
renderItem={({ item }) => <ItemRow item={item} />}
|
|
107
|
+
/>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Filtering Patterns
|
|
113
|
+
|
|
114
|
+
### Simple Text Filter
|
|
115
|
+
|
|
116
|
+
```tsx
|
|
117
|
+
const filtered = items.filter(item =>
|
|
118
|
+
item.name.toLowerCase().includes(search.toLowerCase())
|
|
119
|
+
);
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Multiple Fields
|
|
123
|
+
|
|
124
|
+
```tsx
|
|
125
|
+
const filtered = items.filter(item => {
|
|
126
|
+
const query = search.toLowerCase();
|
|
127
|
+
return (
|
|
128
|
+
item.name.toLowerCase().includes(query) ||
|
|
129
|
+
item.description.toLowerCase().includes(query) ||
|
|
130
|
+
item.tags.some(tag => tag.toLowerCase().includes(query))
|
|
131
|
+
);
|
|
132
|
+
});
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Debounced Search
|
|
136
|
+
|
|
137
|
+
For expensive filtering or API calls:
|
|
138
|
+
|
|
139
|
+
```tsx
|
|
140
|
+
import { useState, useEffect, useMemo } from "react";
|
|
141
|
+
|
|
142
|
+
function useDebounce<T>(value: T, delay: number): T {
|
|
143
|
+
const [debounced, setDebounced] = useState(value);
|
|
144
|
+
|
|
145
|
+
useEffect(() => {
|
|
146
|
+
const timer = setTimeout(() => setDebounced(value), delay);
|
|
147
|
+
return () => clearTimeout(timer);
|
|
148
|
+
}, [value, delay]);
|
|
149
|
+
|
|
150
|
+
return debounced;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function SearchScreen() {
|
|
154
|
+
const search = useSearch();
|
|
155
|
+
const debouncedSearch = useDebounce(search, 300);
|
|
156
|
+
|
|
157
|
+
const filteredItems = useMemo(() =>
|
|
158
|
+
items.filter(item =>
|
|
159
|
+
item.name.toLowerCase().includes(debouncedSearch.toLowerCase())
|
|
160
|
+
),
|
|
161
|
+
[debouncedSearch]
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
return <FlatList data={filteredItems} />;
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Search with Native Tabs
|
|
169
|
+
|
|
170
|
+
When using NativeTabs with a search role, the search bar integrates with the tab bar:
|
|
171
|
+
|
|
172
|
+
```tsx
|
|
173
|
+
// app/_layout.tsx
|
|
174
|
+
<NativeTabs>
|
|
175
|
+
<NativeTabs.Trigger name="(home)">
|
|
176
|
+
<Label>Home</Label>
|
|
177
|
+
<Icon sf="house.fill" />
|
|
178
|
+
</NativeTabs.Trigger>
|
|
179
|
+
<NativeTabs.Trigger name="(search)" role="search">
|
|
180
|
+
<Label>Search</Label>
|
|
181
|
+
</NativeTabs.Trigger>
|
|
182
|
+
</NativeTabs>
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
```tsx
|
|
186
|
+
// app/(search)/_layout.tsx
|
|
187
|
+
<Stack>
|
|
188
|
+
<Stack.Screen
|
|
189
|
+
name="index"
|
|
190
|
+
options={{
|
|
191
|
+
headerSearchBarOptions: {
|
|
192
|
+
placeholder: "Search...",
|
|
193
|
+
onChangeText: (e) => setSearch(e.nativeEvent.text),
|
|
194
|
+
},
|
|
195
|
+
}}
|
|
196
|
+
/>
|
|
197
|
+
</Stack>
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Empty States
|
|
201
|
+
|
|
202
|
+
Show appropriate UI when search returns no results:
|
|
203
|
+
|
|
204
|
+
```tsx
|
|
205
|
+
function SearchResults({ search, items }) {
|
|
206
|
+
const filtered = items.filter(/* ... */);
|
|
207
|
+
|
|
208
|
+
if (search && filtered.length === 0) {
|
|
209
|
+
return (
|
|
210
|
+
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
|
|
211
|
+
<Text style={{ color: colors.secondaryLabel }}>
|
|
212
|
+
No results for "{search}"
|
|
213
|
+
</Text>
|
|
214
|
+
</View>
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return <FlatList data={filtered} />;
|
|
219
|
+
}
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## Search Suggestions
|
|
223
|
+
|
|
224
|
+
Show recent searches or suggestions:
|
|
225
|
+
|
|
226
|
+
```tsx
|
|
227
|
+
function SearchScreen() {
|
|
228
|
+
const search = useSearch();
|
|
229
|
+
const [recentSearches, setRecentSearches] = useState<string[]>([]);
|
|
230
|
+
|
|
231
|
+
if (!search && recentSearches.length > 0) {
|
|
232
|
+
return (
|
|
233
|
+
<View>
|
|
234
|
+
<Text style={{ color: colors.secondaryLabel }}>
|
|
235
|
+
Recent Searches
|
|
236
|
+
</Text>
|
|
237
|
+
{recentSearches.map((term) => (
|
|
238
|
+
<Pressable key={term} onPress={() => /* apply search */}>
|
|
239
|
+
<Text>{term}</Text>
|
|
240
|
+
</Pressable>
|
|
241
|
+
))}
|
|
242
|
+
</View>
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return <SearchResults search={search} />;
|
|
247
|
+
}
|
|
248
|
+
```
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# Storage
|
|
2
|
+
|
|
3
|
+
## Key-Value Storage
|
|
4
|
+
|
|
5
|
+
Use the localStorage polyfill for key-value storage. **Never use AsyncStorage**
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
import "expo-sqlite/localStorage/install";
|
|
9
|
+
|
|
10
|
+
// Simple get/set
|
|
11
|
+
localStorage.setItem("key", "value");
|
|
12
|
+
localStorage.getItem("key");
|
|
13
|
+
|
|
14
|
+
// Store objects as JSON
|
|
15
|
+
localStorage.setItem("user", JSON.stringify({ name: "John", id: 1 }));
|
|
16
|
+
const user = JSON.parse(localStorage.getItem("user") ?? "{}");
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## When to Use What
|
|
20
|
+
|
|
21
|
+
| Use Case | Solution |
|
|
22
|
+
| ---------------------------------------------------- | ----------------------- |
|
|
23
|
+
| Simple key-value (settings, preferences, small data) | `localStorage` polyfill |
|
|
24
|
+
| Large datasets, complex queries, relational data | Full `expo-sqlite` |
|
|
25
|
+
| Sensitive data (tokens, passwords) | `expo-secure-store` |
|
|
26
|
+
|
|
27
|
+
## Storage with React State
|
|
28
|
+
|
|
29
|
+
Create a storage utility with subscriptions for reactive updates:
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
// utils/storage.ts
|
|
33
|
+
import "expo-sqlite/localStorage/install";
|
|
34
|
+
|
|
35
|
+
type Listener = () => void;
|
|
36
|
+
const listeners = new Map<string, Set<Listener>>();
|
|
37
|
+
|
|
38
|
+
export const storage = {
|
|
39
|
+
get<T>(key: string, defaultValue: T): T {
|
|
40
|
+
const value = localStorage.getItem(key);
|
|
41
|
+
return value ? JSON.parse(value) : defaultValue;
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
set<T>(key: string, value: T): void {
|
|
45
|
+
localStorage.setItem(key, JSON.stringify(value));
|
|
46
|
+
listeners.get(key)?.forEach((fn) => fn());
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
subscribe(key: string, listener: Listener): () => void {
|
|
50
|
+
if (!listeners.has(key)) listeners.set(key, new Set());
|
|
51
|
+
listeners.get(key)!.add(listener);
|
|
52
|
+
return () => listeners.get(key)?.delete(listener);
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## React Hook for Storage
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
// hooks/use-storage.ts
|
|
61
|
+
import { useSyncExternalStore } from "react";
|
|
62
|
+
import { storage } from "@/utils/storage";
|
|
63
|
+
|
|
64
|
+
export function useStorage<T>(
|
|
65
|
+
key: string,
|
|
66
|
+
defaultValue: T
|
|
67
|
+
): [T, (value: T) => void] {
|
|
68
|
+
const value = useSyncExternalStore(
|
|
69
|
+
(cb) => storage.subscribe(key, cb),
|
|
70
|
+
() => storage.get(key, defaultValue)
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
return [value, (newValue: T) => storage.set(key, newValue)];
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Usage:
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
function Settings() {
|
|
81
|
+
const [theme, setTheme] = useStorage("theme", "light");
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<Switch
|
|
85
|
+
value={theme === "dark"}
|
|
86
|
+
onValueChange={(dark) => setTheme(dark ? "dark" : "light")}
|
|
87
|
+
/>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Full SQLite for Complex Data
|
|
93
|
+
|
|
94
|
+
For larger datasets or complex queries, use expo-sqlite directly:
|
|
95
|
+
|
|
96
|
+
```tsx
|
|
97
|
+
import * as SQLite from "expo-sqlite";
|
|
98
|
+
|
|
99
|
+
const db = await SQLite.openDatabaseAsync("app.db");
|
|
100
|
+
|
|
101
|
+
// Create table
|
|
102
|
+
await db.execAsync(`
|
|
103
|
+
CREATE TABLE IF NOT EXISTS events (
|
|
104
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
105
|
+
title TEXT NOT NULL,
|
|
106
|
+
date TEXT NOT NULL,
|
|
107
|
+
location TEXT
|
|
108
|
+
)
|
|
109
|
+
`);
|
|
110
|
+
|
|
111
|
+
// Insert
|
|
112
|
+
await db.runAsync("INSERT INTO events (title, date) VALUES (?, ?)", [
|
|
113
|
+
"Meeting",
|
|
114
|
+
"2024-01-15",
|
|
115
|
+
]);
|
|
116
|
+
|
|
117
|
+
// Query
|
|
118
|
+
const events = await db.getAllAsync("SELECT * FROM events WHERE date > ?", [
|
|
119
|
+
"2024-01-01",
|
|
120
|
+
]);
|
|
121
|
+
```
|