Skip to content

Commit 113caa8

Browse files
committed
chore(demo): a GitHub link in the corner, and a clearer switch between the demos
1 parent dd1727b commit 113caa8

2 files changed

Lines changed: 107 additions & 13 deletions

File tree

‎example/src/App.web.tsx‎

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,36 @@ const Link = ({ label, href }: { label: string; href: string }) => (
6161
</Text>
6262
);
6363

64+
const REPOSITORY = "https://github.com/andreialecu/react-native-webcodecs";
65+
66+
// The GitHub mark, 16×16.
67+
const GITHUB_MARK =
68+
"M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z";
69+
70+
// Pinned to the top right corner, over the page.
71+
const GitHubLink = () => (
72+
<View style={styles.github}>
73+
<Text
74+
style={styles.githubLink}
75+
{...({
76+
href: REPOSITORY,
77+
hrefAttrs: { target: "_blank", rel: "noopener" },
78+
accessibilityLabel: "Source code on GitHub",
79+
} as object)}
80+
>
81+
<svg
82+
width={18}
83+
height={18}
84+
viewBox="0 0 16 16"
85+
style={{ verticalAlign: "-3px" }}
86+
>
87+
<path fill="currentColor" d={GITHUB_MARK} />
88+
</svg>
89+
{" "}GitHub
90+
</Text>
91+
</View>
92+
);
93+
6494
const Check = ({ ok, label }: { ok: boolean; label: string }) => (
6595
<View style={styles.check}>
6696
<View
@@ -125,11 +155,16 @@ function App() {
125155

126156
<Segmented
127157
options={[
128-
{ value: "export", label: "Export a Lottie" },
129-
{ value: "compress", label: "Compress a video" },
158+
{ value: "export", label: "Export a Lottie", icon: "sparkle" },
159+
{
160+
value: "compress",
161+
label: "Compress a video",
162+
icon: "compress",
163+
},
130164
]}
131165
value={demo}
132166
onChange={setDemo}
167+
accent
133168
style={styles.demos}
134169
/>
135170

@@ -219,11 +254,31 @@ function App() {
219254
)}
220255
</View>
221256
</ScrollView>
257+
<GitHubLink />
222258
</SafeAreaProvider>
223259
);
224260
}
225261

226262
const styles = StyleSheet.create({
263+
github: {
264+
// Web only: stays in the corner while the page scrolls.
265+
position: "fixed",
266+
top: 16,
267+
right: 16,
268+
zIndex: 10,
269+
} as object,
270+
githubLink: {
271+
color: colors.text,
272+
fontSize: 14,
273+
fontWeight: "600",
274+
paddingVertical: 8,
275+
paddingHorizontal: 14,
276+
borderRadius: 20,
277+
borderWidth: 1,
278+
borderColor: "rgba(255, 255, 255, 0.18)",
279+
backgroundColor: "rgba(18, 12, 34, 0.85)",
280+
backdropFilter: "blur(8px)",
281+
} as object,
227282
page: {
228283
flex: 1,
229284
backgroundColor: colors.background,

‎example/src/VideoExport/ui.tsx‎

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ const icons = {
2525
redo: "M20 12 A8 8 0 1 1 17.66 6.34 M20 4 L20 9 L15 9",
2626
// Two arrows pointing in: make smaller.
2727
compress: "M4 4 L10 10 M10 5 L10 10 L5 10 M20 20 L14 14 M14 19 L14 14 L19 14",
28+
// A four-pointed sparkle.
29+
sparkle:
30+
"M12 3 L13.8 10.2 L21 12 L13.8 13.8 L12 21 L10.2 13.8 L3 12 L10.2 10.2 Z",
2831
// A film frame with a plus.
2932
video:
3033
"M4 6 L15 6 L15 18 L4 18 Z M15 10 L20 7 L20 17 L15 14 M9.5 9.5 L9.5 14.5 M7 12 L12 12",
@@ -124,37 +127,56 @@ export const PillButton = ({
124127
);
125128
};
126129

130+
// `accent` fills the selected option with the accent color, for a switch
131+
// that has to stand out (the web page's choice of demo).
127132
export const Segmented = <T extends string>({
128133
options,
129134
value,
130135
onChange,
131136
disabled,
132137
style,
138+
accent,
133139
}: {
134-
options: { value: T; label: string }[];
140+
options: { value: T; label: string; icon?: keyof typeof icons }[];
135141
value: T;
136142
onChange: (value: T) => void;
137143
disabled?: boolean;
138144
style?: ViewStyle;
145+
accent?: boolean;
139146
}) => (
140-
<View style={[styles.segmented, disabled && { opacity: 0.5 }, style]}>
147+
<View
148+
style={[
149+
styles.segmented,
150+
accent && styles.segmentedAccent,
151+
disabled && { opacity: 0.5 },
152+
style,
153+
]}
154+
>
141155
{options.map((option) => {
142156
const selected = option.value === value;
157+
let color = selected ? colors.text : colors.textDim;
158+
if (accent) {
159+
color = selected ? colors.onAccent : colors.text;
160+
}
143161
return (
144162
<Pressable
145163
key={option.value}
146164
disabled={disabled}
147165
onPress={() => onChange(option.value)}
148-
style={[styles.segment, selected && styles.segmentSelected]}
166+
// react-native-web adds `hovered` to the state.
167+
style={(state) => [
168+
styles.segment,
169+
accent && styles.segmentTall,
170+
selected && styles.segmentSelected,
171+
selected && accent && styles.segmentSelectedAccent,
172+
!selected &&
173+
accent &&
174+
(state as { hovered?: boolean }).hovered &&
175+
styles.segmentHovered,
176+
]}
149177
>
150-
<Text
151-
style={[
152-
styles.segmentLabel,
153-
{ color: selected ? colors.text : colors.textDim },
154-
]}
155-
>
156-
{option.label}
157-
</Text>
178+
{option.icon && <Icon name={option.icon} color={color} size={18} />}
179+
<Text style={[styles.segmentLabel, { color }]}>{option.label}</Text>
158180
</Pressable>
159181
);
160182
})}
@@ -203,16 +225,33 @@ const styles = StyleSheet.create({
203225
borderWidth: StyleSheet.hairlineWidth,
204226
borderColor: colors.border,
205227
},
228+
segmentedAccent: {
229+
borderRadius: 26,
230+
borderWidth: 1,
231+
borderColor: "rgba(60, 227, 246, 0.35)",
232+
},
206233
segment: {
207234
flex: 1,
208235
height: 36,
209236
borderRadius: 18,
237+
flexDirection: "row",
238+
gap: 8,
210239
alignItems: "center",
211240
justifyContent: "center",
212241
},
242+
segmentTall: {
243+
height: 44,
244+
borderRadius: 22,
245+
},
213246
segmentSelected: {
214247
backgroundColor: colors.surfaceRaised,
215248
},
249+
segmentSelectedAccent: {
250+
backgroundColor: colors.accent,
251+
},
252+
segmentHovered: {
253+
backgroundColor: colors.surfaceRaised,
254+
},
216255
segmentLabel: {
217256
fontSize: 14,
218257
fontWeight: "600",

0 commit comments

Comments
 (0)