-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: added runnable examples subdir and updated README accordingly
- Loading branch information
Showing
20 changed files
with
14,667 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
.github/ | ||
node_modules/ | ||
|
||
rndp-examples | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Learn more https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files | ||
|
||
# dependencies | ||
node_modules/ | ||
|
||
# Expo | ||
.expo/ | ||
dist/ | ||
web-build/ | ||
|
||
# Native | ||
*.orig.* | ||
*.jks | ||
*.p8 | ||
*.p12 | ||
*.key | ||
*.mobileprovision | ||
|
||
# Metro | ||
.metro-health-check* | ||
|
||
# debug | ||
npm-debug.* | ||
yarn-debug.* | ||
yarn-error.* | ||
|
||
# macOS | ||
.DS_Store | ||
*.pem | ||
|
||
# local env files | ||
.env*.local | ||
|
||
# typescript | ||
*.tsbuildinfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
import React, { JSX } from 'react'; | ||
import { StyleSheet, Text, View } from 'react-native'; | ||
import DropDownPicker, { ItemType } from 'react-native-dropdown-picker'; | ||
import JavascriptClassExample from './javascript-class-example'; | ||
import JavascriptFunctionExample from './javascript-function-example'; | ||
import TypescriptClassExample from './typescript-class-example'; | ||
import TypescriptFunctionExample from './typescript-function-example'; | ||
|
||
enum ExampleComponent { | ||
JavaScriptClassSingleValue, | ||
JavaScriptClassMultiValue, | ||
JavaScriptFunctionSingleValue, | ||
JavaScriptFunctionMultiValue, | ||
TypeScriptClassSingleValue, | ||
TypeScriptClassMultiValue, | ||
TypeScriptFunctionSingleValue, | ||
TypeScriptFunctionMultiValue, | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
// backgroundColor: "#fff", | ||
// alignItems: "center", | ||
// justifyContent: "center", | ||
flexDirection: 'column', | ||
margin: 3, | ||
marginTop: 20, | ||
padding: 3, | ||
}, | ||
}); | ||
|
||
const EXAMPLE_COMPONENT_ITEMS: Array<ItemType<ExampleComponent>> = [ | ||
{ | ||
label: 'JavaScript; class component; single-item', | ||
value: ExampleComponent.JavaScriptClassSingleValue, | ||
}, | ||
{ | ||
label: 'JavaScript; class component; multiple-item', | ||
value: ExampleComponent.JavaScriptClassMultiValue, | ||
}, | ||
{ | ||
label: 'JavaScript; function component; single-item', | ||
value: ExampleComponent.JavaScriptFunctionSingleValue, | ||
}, | ||
{ | ||
label: 'JavaScript; function component; multiple-item', | ||
value: ExampleComponent.JavaScriptFunctionMultiValue, | ||
}, | ||
{ | ||
label: 'TypeScript; class component; single-item', | ||
value: ExampleComponent.TypeScriptClassSingleValue, | ||
}, | ||
{ | ||
label: 'TypeScript; class component; multiple-item', | ||
value: ExampleComponent.TypeScriptClassMultiValue, | ||
}, | ||
{ | ||
label: 'TypeScript; function component; single-item', | ||
value: ExampleComponent.TypeScriptFunctionSingleValue, | ||
}, | ||
{ | ||
label: 'TypeScript; function component; multiple-item', | ||
value: ExampleComponent.TypeScriptFunctionMultiValue, | ||
}, | ||
]; | ||
|
||
type Props = Record<string, never>; | ||
type State = { | ||
currentExample: ExampleComponent; | ||
examplePickerOpen: boolean; | ||
exampleComponents: Array<ItemType<ExampleComponent>>; | ||
}; | ||
|
||
export default class App extends React.Component<Props, State> { | ||
constructor(props: Readonly<Props>) { | ||
super(props); | ||
this.state = { | ||
currentExample: ExampleComponent.JavaScriptClassSingleValue, | ||
exampleComponents: EXAMPLE_COMPONENT_ITEMS, | ||
examplePickerOpen: false, | ||
}; | ||
|
||
this.setOpen = this.setOpen.bind(this); | ||
this.setCurrentExample = this.setCurrentExample.bind(this); | ||
} | ||
|
||
private static getExample(egComponent: ExampleComponent): JSX.Element { | ||
switch (egComponent) { | ||
case ExampleComponent.JavaScriptClassSingleValue: | ||
return <JavascriptClassExample multiple={false} />; | ||
case ExampleComponent.JavaScriptClassMultiValue: | ||
return <JavascriptClassExample multiple />; | ||
case ExampleComponent.JavaScriptFunctionSingleValue: | ||
return <JavascriptFunctionExample multiple={false} />; | ||
case ExampleComponent.JavaScriptFunctionMultiValue: | ||
return <JavascriptFunctionExample multiple />; | ||
case ExampleComponent.TypeScriptClassSingleValue: | ||
return <TypescriptClassExample multiple={false} />; | ||
case ExampleComponent.TypeScriptClassMultiValue: | ||
return <TypescriptClassExample multiple />; | ||
case ExampleComponent.TypeScriptFunctionSingleValue: | ||
return <TypescriptFunctionExample multiple={false} />; | ||
case ExampleComponent.TypeScriptFunctionMultiValue: | ||
return <TypescriptFunctionExample multiple />; | ||
default: | ||
throw new Error( | ||
"couldn't match example component in getExample() in App.tsx. egComponent was: ", | ||
egComponent, | ||
); | ||
} | ||
} | ||
|
||
setOpen(examplePickerOpen: boolean): void { | ||
this.setState({ examplePickerOpen }); | ||
} | ||
|
||
setCurrentExample( | ||
callback: (prevState: ExampleComponent | null) => ExampleComponent | null, | ||
): void { | ||
this.setState((state: Readonly<State>) => ({ | ||
currentExample: callback(state.currentExample), | ||
})); | ||
} | ||
|
||
// todo: fix picker items being under text | ||
|
||
render(): JSX.Element { | ||
const { currentExample, examplePickerOpen, exampleComponents } = this.state; | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<View style={{ flex: 1 }}> | ||
<View style={{ flex: 1 }}> | ||
<Text>Choose example:</Text> | ||
</View> | ||
|
||
<View style={{ flex: 1 }}> | ||
<DropDownPicker | ||
setValue={this.setCurrentExample} | ||
value={currentExample} | ||
items={exampleComponents} | ||
open={examplePickerOpen} | ||
setOpen={this.setOpen} | ||
/> | ||
</View> | ||
</View> | ||
|
||
<View style={{ flex: 3 }}> | ||
<View style={{ flex: 1 }}> | ||
<Text>Example:</Text> | ||
</View> | ||
|
||
{App.getExample(currentExample)} | ||
</View> | ||
</View> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"expo": { | ||
"name": "rndp-examples", | ||
"slug": "rndp-examples", | ||
"version": "1.0.0", | ||
"orientation": "portrait", | ||
"icon": "./assets/icon.png", | ||
"userInterfaceStyle": "light", | ||
"splash": { | ||
"image": "./assets/splash.png", | ||
"resizeMode": "contain", | ||
"backgroundColor": "#ffffff" | ||
}, | ||
"assetBundlePatterns": [ | ||
"**/*" | ||
], | ||
"ios": { | ||
"supportsTablet": true | ||
}, | ||
"android": { | ||
"adaptiveIcon": { | ||
"foregroundImage": "./assets/adaptive-icon.png", | ||
"backgroundColor": "#ffffff" | ||
} | ||
}, | ||
"web": { | ||
"favicon": "./assets/favicon.png" | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = function (api) { | ||
api.cache(true); | ||
return { | ||
presets: ['babel-preset-expo'], | ||
}; | ||
}; |
Oops, something went wrong.