Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: improve Example apps #2460

Merged
merged 78 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
d468229
Init commit
stanleyoos Sep 19, 2024
e1892d5
feat: transformed class components into funtcional
stanleyoos Sep 20, 2024
c896b9f
feat: Added few titles to examples
stanleyoos Sep 20, 2024
092e99e
feat: Transformed all classes components into functional ones
stanleyoos Sep 20, 2024
279f9ae
feat: Deleted comments
stanleyoos Sep 20, 2024
512ecf2
feat: Created screens for FiltersExample
stanleyoos Sep 25, 2024
371b5b9
feat: Created screens for FilterImages examples
stanleyoos Sep 25, 2024
36a18ae
feat: Made one param optional
stanleyoos Sep 25, 2024
d0e4805
test: Changed E2E tests
stanleyoos Sep 25, 2024
dc66cf7
feat: Added new dependencies to fabric-example
stanleyoos Sep 25, 2024
8715511
feat: Created commonStyles file
stanleyoos Sep 26, 2024
c2dec79
Merge branch 'main' into @stanleyoos/feat-implement-react-navigation
stanleyoos Sep 26, 2024
ebc53c4
test: Updated package.json to pass the iOS build test
stanleyoos Sep 27, 2024
7c157c5
Update ios-build-test.yml
stanleyoos Sep 27, 2024
64198f5
Revert "test: Updated package.json to pass the iOS build test"
stanleyoos Sep 27, 2024
cb1c6c4
Merge branch '@stanleyoos/feat-implement-react-navigation' of github.…
stanleyoos Sep 27, 2024
08adad1
Reverted package.json to initial form
stanleyoos Sep 27, 2024
3d9c9d6
Update ios-build-test.yml
stanleyoos Sep 27, 2024
39d8d2f
fix: Updated yarn.lock and podfile.lock
stanleyoos Sep 27, 2024
fa89a17
Merge branch '@stanleyoos/feat-implement-react-navigation' of github.…
stanleyoos Sep 27, 2024
3bd7ee8
fix: try to fix androind build error
stanleyoos Sep 27, 2024
8fe57f0
fix: Bumped Gradle version to avoid the error
stanleyoos Sep 27, 2024
69b36ff
fix: Reverted gradle version
stanleyoos Sep 27, 2024
73df018
fix: Added case for E2E tests
stanleyoos Sep 27, 2024
a5ebf3d
fix: Bumped Gradle version for Android build test
stanleyoos Sep 27, 2024
073c96e
fix: restored yarn.lock file
stanleyoos Sep 30, 2024
c5bd081
fix: Updated Graddle version for fabric-example
stanleyoos Sep 30, 2024
ef6dc33
fix: Added missing package react-navigation/native-stack
stanleyoos Sep 30, 2024
2463ee6
feat: Added support for Mac apps
stanleyoos Oct 1, 2024
dbc5213
fix: Added gesture-handler dependency to example app
stanleyoos Oct 1, 2024
2c42e1e
fix: Deleted unused code
stanleyoos Oct 1, 2024
9d9bdb1
Merge branch 'main' of github.com:software-mansion/react-native-svg i…
bohdanprog Oct 4, 2024
1fd1ce2
Merge branch 'main' of github.com:software-mansion/react-native-svg i…
bohdanprog Oct 4, 2024
7c2d88d
chore: update package.json and yarn.lock
bohdanprog Oct 4, 2024
5abe7d0
chore: update tsconfig in apps
bohdanprog Oct 4, 2024
4d76670
chore: change reanimated version to 3.15.4
bohdanprog Oct 4, 2024
b1bd6f6
chore: restore examples file
bohdanprog Oct 4, 2024
fd5bfd2
feat: add to examples title and update export
bohdanprog Oct 4, 2024
b950355
feat: add Expamples type
bohdanprog Oct 4, 2024
3fdbdb6
chore: change header aligment
bohdanprog Oct 4, 2024
8db8367
chore: add title to filter examples
bohdanprog Oct 7, 2024
b887729
fix: update react-native-screen fix problem when return to previous s…
bohdanprog Oct 7, 2024
1d12a0d
feat: create HomeScreen component
bohdanprog Oct 7, 2024
b0fe056
chore: restore examples.windows file, and change type import
bohdanprog Oct 7, 2024
c0530d3
chore: change title in PanResponder example
bohdanprog Oct 7, 2024
f518099
chore: update types
bohdanprog Oct 7, 2024
5b7dd89
feat: create Item and ItemSeparator components
bohdanprog Oct 7, 2024
419dd65
chore: update FilterImage and Filter examples
bohdanprog Oct 7, 2024
89ef37d
chore: add type for useNavigation
bohdanprog Oct 7, 2024
edb2ee4
chore: change export for FilterImageExamples
bohdanprog Oct 7, 2024
0aff5ca
chore: update index.tsx in apps/examples
bohdanprog Oct 7, 2024
123ea6f
chore: update dependencies for paper-macos-example
bohdanprog Oct 7, 2024
9b2793d
chore: restore changes
bohdanprog Oct 7, 2024
3bac0f9
chore: add title to filter examples
bohdanprog Oct 7, 2024
6d314ef
chore: update export for filterExamples
bohdanprog Oct 7, 2024
03f5b23
chore: change import for FilterExamples
bohdanprog Oct 7, 2024
9b5b70e
chore: remove unused styles
bohdanprog Oct 8, 2024
a1e151a
chore: update HomeScreen for macos platform
bohdanprog Oct 8, 2024
764774d
chore: clean examples
bohdanprog Oct 8, 2024
7b86b8d
chore: fixed problem return to the previous screen
bohdanprog Oct 8, 2024
cd48c0b
chore: changed FilterExample import
bohdanprog Oct 8, 2024
9197107
chore: remove unnecessary styles
bohdanprog Oct 8, 2024
dfb7d22
chore: update podfile.lock
bohdanprog Oct 8, 2024
50e89c6
chore: update web example dependencies
bohdanprog Oct 8, 2024
ac0d778
chore: change paddingTop to paddingVertical
bohdanprog Oct 8, 2024
6b14d76
chore: update yarn.lock and Podfile.lock
bohdanprog Oct 9, 2024
a32e9bf
Merge branch 'main' into @stanleyoos/feat-implement-react-navigation
jakex7 Oct 21, 2024
1e3130f
chore: update podfiles
jakex7 Oct 21, 2024
7e6e10b
refactor: remove example from name
jakex7 Oct 21, 2024
6f21131
refactor: move common styles
jakex7 Oct 21, 2024
19de639
refactor: remove title
jakex7 Oct 21, 2024
4374ad5
refactor: deduplicate code
jakex7 Oct 21, 2024
dace03c
remove: title from examples
jakex7 Oct 21, 2024
f0c8590
refactor: restore e2e tests
jakex7 Oct 21, 2024
79d28cd
remove: testing wrapper
jakex7 Oct 21, 2024
4171123
docs: fix Svg example types
jakex7 Oct 21, 2024
a5b2fa6
refactor: fix types
jakex7 Oct 21, 2024
4ccf87a
fix: macos warnings
jakex7 Oct 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
250 changes: 79 additions & 171 deletions apps/examples/index.tsx
Original file line number Diff line number Diff line change
@@ -1,185 +1,93 @@
/**
* Sample React Native App for react-native-svg library
* https://github.com/magicismight/react-native-svg/tree/master/Example
* https://github.com/software-mansion/react-native-svg/tree/main/apps/examples
*/
'use strict';

import React, {Component} from 'react';
import {NavigationContainer} from '@react-navigation/native';
import {createNativeStackNavigator} from '@react-navigation/native-stack';
import {createStackNavigator} from '@react-navigation/stack';
import React from 'react';
import {ActivityIndicator, Platform, View} from 'react-native';
import {GestureHandlerRootView} from 'react-native-gesture-handler';
import {allScreens, allScreensKeys} from './src';
import {ListScreen} from './src/ListScreen';
import * as E2e from './src/e2e';
import {examples} from './src/examples';
import * as FilterImage from './src/examples/FilterImage';
import * as Filters from './src/examples/Filters';
import {commonStyles} from './src/utils/commonStyles';
import composeComponents from './src/utils/composeComponent';
import {
Dimensions,
Modal,
Platform,
SafeAreaView,
ScrollView,
StyleSheet,
Text,
TouchableHighlight,
TouchableOpacity,
View,
} from 'react-native';
import {Circle, Line, Svg} from 'react-native-svg';
Example,
Examples,
NavigationProp,
RootStackParamList,
} from './src/utils/types';
import {usePersistNavigation} from './src/utils/usePersistNavigation';

import {commonStyles} from './src/commonStyles';
import E2eTestingView from './src/e2e';
import * as examples from './src/examples';
import {names} from './utils/names';
export default function App() {
const {isReady, initialState, persistNavigationState} =
usePersistNavigation();

const initialState = {
modal: false,
content: null,
};

export default class SvgExample extends Component {
state: {
content: React.ReactNode;
modal: boolean;
scroll?: boolean;
} = initialState;

show = (name: keyof typeof examples) => {
if (this.state.modal) {
return;
}
let example = examples[name];
if (example) {
let samples = example.samples;
this.setState({
modal: true,
content: (
<View>
{samples.map((Sample, i) => (
<View style={commonStyles.example} key={`sample-${i}`}>
<Text style={commonStyles.sampleTitle}>{Sample.title}</Text>
<Sample />
</View>
))}
</View>
),
scroll: (example as {scroll?: boolean}).scroll !== false,
});
}
};

hide = () => {
this.setState(initialState);
};

getExamples = () => {
return names
.filter(el => {
if (el !== 'E2E') return true;
return Platform.OS === 'android' || Platform.OS === 'ios';
})
.map(name => {
var icon;
let example = examples[name as keyof typeof examples];
if (example) {
icon = example.icon;
}
return (
<TouchableHighlight
style={styles.link}
underlayColor="#ccc"
key={`example-${name}`}
onPress={() => this.show(name as keyof typeof examples)}>
<View style={commonStyles.cell}>
{icon}
<Text style={commonStyles.title}>{name}</Text>
</View>
</TouchableHighlight>
);
});
};

modalContent = () => (
<>
<SafeAreaView style={{flex: 1}}>
<ScrollView
style={styles.scroll}
contentContainerStyle={styles.scrollContent}
scrollEnabled={this.state.scroll}>
{this.state.content}
</ScrollView>
</SafeAreaView>
<SafeAreaView style={styles.close}>
<TouchableOpacity activeOpacity={0.7} onPress={this.hide}>
<Svg height="20" width="20">
<Circle cx="10" cy="10" r="10" fill="red" />
<Line x1="4" y1="4" x2="16" y2="16" stroke="#fff" strokeWidth="2" />
<Line x1="4" y1="16" x2="16" y2="4" stroke="#fff" strokeWidth="2" />
</Svg>
</TouchableOpacity>
</SafeAreaView>
</>
);

render() {
if (process.env.E2E) {
console.log(
'Opening E2E example, as E2E env is set to ' + process.env.E2E,
);
return <E2eTestingView />;
}
if (!isReady) {
return (
<SafeAreaView style={styles.container}>
<Text style={commonStyles.welcome}>SVG library for React Apps</Text>
<View style={styles.contentContainer}>{this.getExamples()}</View>
{(Platform.OS === 'windows' || Platform.OS === 'macos') &&
this.state.modal ? (
<View style={styles.scroll}>{this.modalContent()}</View>
) : (
<Modal
transparent={false}
animationType="fade"
visible={this.state.modal}
onRequestClose={this.hide}>
{this.modalContent()}
</Modal>
)}
</SafeAreaView>
<View style={[commonStyles.container, commonStyles.center]}>
<ActivityIndicator />
</View>
);
}
if (process.env.E2E) {
console.log('Opening E2E example, as E2E env is set to ' + process.env.E2E);
return <E2e.component />;
}
return (
<GestureHandlerRootView style={commonStyles.container}>
<NavigationContainer
initialState={initialState}
onStateChange={persistNavigationState}>
<Stack.Navigator
screenOptions={{headerTintColor: '#f60', headerTitleAlign: 'center'}}>
<Stack.Screen name="RNSVG" component={HomeList} />
<Stack.Screen name="Filters" component={FiltersList} />
<Stack.Screen name="Filter Image" component={FilterImageList} />
{allScreensKeys.map(name => (
<Stack.Screen
key={name}
name={name}
component={composeComponents(
allScreens[name].samples,
(allScreens as Examples)[name].shouldBeRenderInView,
)}
/>
))}
<Stack.Screen name={'E2E'}>{E2e.component}</Stack.Screen>
</Stack.Navigator>
</NavigationContainer>
</GestureHandlerRootView>
);
}

const hairline = StyleSheet.hairlineWidth;
type ScreenProps = {navigation: NavigationProp};
const HomeList = (props: ScreenProps) => (
<ListScreen
{...props}
examples={{
...examples,
Filters,
'Filter Image': FilterImage,
E2E: E2e as unknown as Example,
}}
/>
);
const FiltersList = (props: ScreenProps) => (
<ListScreen {...props} examples={Filters.samples} />
);
const FilterImageList = (props: ScreenProps) => (
<ListScreen {...props} examples={FilterImage.samples} />
);

const styles = StyleSheet.create({
container: {
flex: 1,
paddingTop: 20,
alignItems: 'center',
overflow: 'hidden',
},
contentContainer: {
alignSelf: 'stretch',
borderTopWidth: hairline,
borderTopColor: '#ccc',
borderBottomWidth: hairline,
borderBottomColor: '#ccc',
flexWrap: 'wrap',
flexDirection: 'row',
marginHorizontal: 10,
},
link: {
height: 40,
alignSelf: 'stretch',
width: Dimensions.get('window').width / 2 - 10,
},
close: {
position: 'absolute',
right: 20,
top: 20,
},
scroll: {
position: 'absolute',
top: 30,
right: 10,
bottom: 20,
left: 10,
backgroundColor: '#fff',
},
scrollContent: {
borderTopWidth: hairline,
borderTopColor: '#ccc',
},
});
const Stack =
Platform.OS === 'macos'
? createStackNavigator<RootStackParamList>()
: createNativeStackNavigator<RootStackParamList>();
66 changes: 66 additions & 0 deletions apps/examples/src/ListScreen.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React, {useState} from 'react';
import {
FlatList,
Platform,
Pressable,
Text,
TouchableOpacity,
View,
} from 'react-native';
import {commonStyles} from './utils/commonStyles';
import {Examples, NavigationProp} from './utils/types';

export type ListScreenProps = {
navigation: NavigationProp;
examples: Examples;
};

export function ListScreen({navigation, examples}: ListScreenProps) {
const [wasClicked, setWasClicked] = useState<string[]>([]);

return (
<FlatList
removeClippedSubviews={false}
data={Object.keys(examples) as (keyof typeof examples)[]}
style={commonStyles.list}
contentInsetAdjustmentBehavior="scrollableAxes"
numColumns={Platform.OS === 'macos' ? 2 : 1}
scrollEnabled={Platform.OS !== 'macos'}
renderItem={({item: name}) => (
<Item
icon={examples[name].icon}
title={name}
onPress={() => {
navigation.navigate(name as any);
if (!wasClicked.includes(name)) {
setTimeout(() => setWasClicked([...wasClicked, name]), 500);
}
}}
wasClicked={wasClicked.includes(name)}
/>
)}
ItemSeparatorComponent={ItemSeparator}
/>
);
}

function ItemSeparator() {
return <View style={commonStyles.separator} />;
}
type ItemProps = {
title: string;
onPress: () => void;
icon?: React.ReactNode;
wasClicked?: boolean;
};
function Item({icon, title, onPress, wasClicked}: ItemProps) {
const Button = Platform.OS === 'macos' ? Pressable : TouchableOpacity;
return (
<Button
style={[commonStyles.button, wasClicked && commonStyles.visitedItem]}
onPress={onPress}>
{icon && <View style={{marginRight: 12}}>{icon}</View>}
<Text style={commonStyles.title}>{title}</Text>
</Button>
);
}
41 changes: 0 additions & 41 deletions apps/examples/src/commonStyles.ts

This file was deleted.

Loading
Loading