Skip to content

Commit

Permalink
[Example app] Highlight already visited examples (#5936)
Browse files Browse the repository at this point in the history
## Summary

When manually testing the examples sometimes I get lost and forget what
I already visited. This small QoL PR allows me to not remember at all.


https://github.com/software-mansion/react-native-reanimated/assets/40713406/ebeef801-735b-4f22-8fd0-17dfbcaf3934

## Test plan

🚀
  • Loading branch information
tjzel committed Apr 26, 2024
1 parent 9ea5687 commit 7e1a19e
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions app/src/App.tsx
Expand Up @@ -70,6 +70,7 @@ function HomeScreen({ navigation }: HomeScreenProps) {
// TODO: Currently it breaks on @react-navigation
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [search, setSearch] = React.useState('');
const [wasClicked, setWasClicked] = React.useState<string[]>([]);

React.useLayoutEffect(() => {
// TODO: Currently it breaks on @react-navigation
Expand Down Expand Up @@ -97,8 +98,14 @@ function HomeScreen({ navigation }: HomeScreenProps) {
<Item
icon={EXAMPLES[name].icon}
title={EXAMPLES[name].title}
onPress={() => navigation.navigate(name)}
onPress={() => {
navigation.navigate(name);
if (!wasClicked.includes(name)) {
setTimeout(() => setWasClicked([...wasClicked, name]), 500);
}
}}
missingOnFabric={EXAMPLES[name].missingOnFabric}
wasClicked={wasClicked.includes(name)}
/>
)}
renderScrollComponent={(props) => <ScrollView {...props} />}
Expand All @@ -113,30 +120,30 @@ interface ItemProps {
title: string;
onPress: () => void;
missingOnFabric?: boolean;
wasClicked?: boolean;
}

function Item({ icon, title, onPress, missingOnFabric }: ItemProps) {
function Item({
icon,
title,
onPress,
missingOnFabric,
wasClicked,
}: ItemProps) {
const isDisabled = missingOnFabric && isFabric();
if (Platform.OS === 'macos') {
return (
<Pressable
style={[styles.button, isDisabled && styles.disabledButton]}
onPress={onPress}
disabled={isDisabled}>
{icon && <Text style={styles.title}>{icon + ' '}</Text>}
<Text style={styles.title}>{title}</Text>
</Pressable>
);
}

const Button = Platform.OS === 'macos' ? Pressable : RectButton;
return (
<RectButton
style={[styles.button, isDisabled && styles.disabledButton]}
<Button
style={[
styles.button,
isDisabled && styles.disabledButton,
wasClicked && styles.visitedItem,
]}
onPress={onPress}
enabled={!isDisabled}>
{icon && <Text style={styles.title}>{icon + ' '}</Text>}
<Text style={styles.title}>{title}</Text>
</RectButton>
</Button>
);
}

Expand Down Expand Up @@ -285,4 +292,7 @@ const styles = StyleSheet.create({
fontSize: 16,
color: 'black',
},
visitedItem: {
backgroundColor: '#e6f0f7',
},
});

0 comments on commit 7e1a19e

Please sign in to comment.