Skip to content

Commit ca0d63e

Browse files
authored
Disable examples on unsupported platforms (#3135)
## Description Some of our examples are platform-specific, which means that running them on other platforms doesn't make much sense. In this PR I've disabled navigation buttons so that opening such examples is not possible on unsupported platforms. E.g.: _**Web styles reset**_ works only on `web`. After this PR you'll no longer be able to open it on other platforms, like `ios` or `android`. <img width="329" alt="image" src="https://github.com/user-attachments/assets/847b25b0-d305-4787-ad24-aca399811a5a"> ## Test plan Go through example app
1 parent 77c5f37 commit ca0d63e

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

example/App.tsx

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ import { Icon } from '@swmansion/icons';
8686
interface Example {
8787
name: string;
8888
component: React.ComponentType;
89+
unsupportedPlatforms?: Set<typeof Platform.OS>;
8990
}
9091
interface ExamplesSection {
9192
sectionTitle: string;
@@ -130,8 +131,16 @@ const EXAMPLES: ExamplesSection[] = [
130131
{ name: 'Bouncing box', component: BouncingBox },
131132
{ name: 'Pan responder', component: PanResponder },
132133
{ name: 'Horizontal drawer', component: HorizontalDrawer },
133-
{ name: 'Pager & drawer', component: PagerAndDrawer },
134-
{ name: 'Force touch', component: ForceTouch },
134+
{
135+
name: 'Pager & drawer',
136+
component: PagerAndDrawer,
137+
unsupportedPlatforms: new Set(['web', 'ios', 'macos']),
138+
},
139+
{
140+
name: 'Force touch',
141+
component: ForceTouch,
142+
unsupportedPlatforms: new Set(['web', 'android', 'macos']),
143+
},
135144
{ name: 'Fling', component: Fling },
136145
],
137146
},
@@ -170,8 +179,9 @@ const EXAMPLES: ExamplesSection[] = [
170179
component: NestedPressables as React.ComponentType,
171180
},
172181
{
173-
name: 'Nested buttons (sound & ripple on Android)',
182+
name: 'Nested buttons (sound & ripple)',
174183
component: NestedButtons,
184+
unsupportedPlatforms: new Set(['web', 'ios', 'macos']),
175185
},
176186
{ name: 'Double pinch & rotate', component: DoublePinchRotate },
177187
{ name: 'Double draggable', component: DoubleDraggable },
@@ -180,12 +190,20 @@ const EXAMPLES: ExamplesSection[] = [
180190
{ name: 'Combo', component: ComboWithGHScroll },
181191
{ name: 'Touchables', component: TouchablesIndex as React.ComponentType },
182192
{ name: 'MouseButtons', component: MouseButtons },
183-
{ name: 'ContextMenu (web only)', component: ContextMenu },
193+
{
194+
name: 'ContextMenu',
195+
component: ContextMenu,
196+
unsupportedPlatforms: new Set(['android', 'ios', 'macos']),
197+
},
184198
{ name: 'PointerType', component: PointerType },
185199
{ name: 'Swipeable Reanimation', component: SwipeableReanimation },
186200
{ name: 'RectButton (borders)', component: RectButtonBorders },
187201
{ name: 'Gesturized pressable', component: GesturizedPressable },
188-
{ name: 'Web styles reset', component: WebStylesResetExample },
202+
{
203+
name: 'Web styles reset',
204+
component: WebStylesResetExample,
205+
unsupportedPlatforms: new Set(['android', 'ios', 'macos']),
206+
},
189207
{ name: 'Stylus data', component: StylusData },
190208
],
191209
},
@@ -285,6 +303,7 @@ function MainScreen({ navigation }: StackScreenProps<ParamListBase>) {
285303
<MainScreenItem
286304
name={item.name}
287305
onPressItem={(name) => navigate(navigation, name)}
306+
enabled={!item.unsupportedPlatforms?.has(Platform.OS)}
288307
/>
289308
)}
290309
renderSectionHeader={({ section: { sectionTitle } }) => (
@@ -334,13 +353,17 @@ function OpenLastExampleSetting() {
334353
interface MainScreenItemProps {
335354
name: string;
336355
onPressItem: (name: string) => void;
356+
enabled: boolean;
337357
}
338358

339-
function MainScreenItem({ name, onPressItem }: MainScreenItemProps) {
359+
function MainScreenItem({ name, onPressItem, enabled }: MainScreenItemProps) {
340360
return (
341-
<RectButton style={[styles.button]} onPress={() => onPressItem(name)}>
361+
<RectButton
362+
enabled={enabled}
363+
style={[styles.button, !enabled && styles.unavailableExample]}
364+
onPress={() => onPressItem(name)}>
342365
<Text style={styles.text}>{name}</Text>
343-
{Platform.OS !== 'macos' && (
366+
{Platform.OS !== 'macos' && enabled && (
344367
<Icon name="chevron-small-right" size={24} color="#bbb" />
345368
)}
346369
</RectButton>
@@ -406,4 +429,8 @@ const styles = StyleSheet.create({
406429
}
407430
: {}),
408431
},
432+
unavailableExample: {
433+
backgroundColor: 'rgb(220, 220, 220)',
434+
opacity: 0.3,
435+
},
409436
});

0 commit comments

Comments
 (0)