Skip to content

Commit

Permalink
chore: added runnable examples subdir and updated README accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
taeh98 committed Sep 5, 2023
1 parent e3f4d09 commit 21b2eb9
Show file tree
Hide file tree
Showing 20 changed files with 14,665 additions and 287 deletions.
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.github/
node_modules/

examples
package-lock.json
34 changes: 18 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
# React Native Dropdown Picker

<p align="left">
<a href="https://github.com/hossein-zare/react-native-dropdown-picker/blob/dev-5.x/LICENSE">
<img src="https://img.shields.io/badge/license-MIT-blue.svg"
alt="react-native-dropdown-picker is released under the MIT license." />
</a>
<a href="https://www.npmjs.org/package/react-native-dropdown-picker">
<img src="https://img.shields.io/npm/v/react-native-dropdown-picker?color=brightgreen&label=npm%20package"
alt="Current npm package version." />
</a>
</p>
[![react-native-dropdown-picker is released under the MIT license.](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/hossein-zare/react-native-dropdown-picker/blob/dev-5.x/LICENSE)
[![Current npm package version.](https://img.shields.io/npm/v/react-native-dropdown-picker?color=brightgreen&label=npm%20package)](https://www.npmjs.org/package/react-native-dropdown-picker)

[//]: # (TODO: add badge linking to GitHub repo)

---

## Screenshots

Expand All @@ -22,17 +18,24 @@
width="270" alt="Screenshot showing dark theme and parent items" />
</p>

The above screenshots are taken from the following
example: [https://snack.expo.dev/8mHmLfcZf](https://snack.expo.dev/8mHmLfcZf)
The above screenshots were taken
from [this example](https://snack.expo.dev/8mHmLfcZf).

## Usage

See [the relevant documentation](https://hossein-zare.github.io/react-native-dropdown-picker-website/docs/usage).
You can find runnable examples in the `examples` subdirectory, which is a
working [Expo](https://github.com/expo/expo) project demonstrating this library.
Navigate into the `examples` subdirectory, run `npm install`, and then run
`npx expo start` to see the examples working.

For further information on how to use this library,
read [the relevant documentation](https://hossein-zare.github.io/react-native-dropdown-picker-website/docs/usage).

## Further documentation

The docs can be read
at: [https://hossein-zare.github.io/react-native-dropdown-picker-website](https://hossein-zare.github.io/react-native-dropdown-picker-website).

The docs can be edited
at: [https://github.com/hossein-zare/react-native-dropdown-picker-website](https://github.com/hossein-zare/react-native-dropdown-picker-website)

Expand Down Expand Up @@ -60,9 +63,8 @@ To make a new release, follow these steps:
works well
* You can test changes to the library and experiment easily
with [patch-package](https://www.npmjs.com/package/patch-package)
* Use `npm pack` to test the new version of the library locally and check it
works correctly;
see [https://dev.to/scooperdev/use-npm-pack-to-test-your-packages-locally-486e](https://dev.to/scooperdev/use-npm-pack-to-test-your-packages-locally-486e)
* Once you have made changes, and after finalizing them, use `npm pack`
to [test your new, changed version of the library locally and check it works correctly](https://dev.to/scooperdev/use-npm-pack-to-test-your-packages-locally-486e)
* Make and merge a final PR into the development branch that increments the
version number in `package.json`
* Make and merge a PR from the development branch to the release branch
Expand Down
35 changes: 35 additions & 0 deletions examples/.gitignore
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
159 changes: 159 additions & 0 deletions examples/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import React, { JSX } from 'react';

Check failure on line 1 in examples/App.tsx

View workflow job for this annotation

GitHub Actions / Lint source files

Missing @file
import { StyleSheet, Text, View } from 'react-native';
import DropDownPicker, { ItemType } from 'react-native-dropdown-picker';

Check failure on line 3 in examples/App.tsx

View workflow job for this annotation

GitHub Actions / Lint source files

Imports should be sorted alphabetically

Check failure on line 3 in examples/App.tsx

View workflow job for this annotation

GitHub Actions / Lint source files

Unable to resolve path to module 'react-native-dropdown-picker'
import JavascriptClassExample from './example-src-files/javascript-class-example';
import JavascriptFunctionExample from './example-src-files/javascript-function-example';
import TypescriptClassExample from './example-src-files/typescript-class-example';
import TypescriptFunctionExample from './example-src-files/typescript-function-example';

enum ExampleComponent {

Check failure on line 9 in examples/App.tsx

View workflow job for this annotation

GitHub Actions / Lint source files

'ExampleComponent' is already declared in the upper scope on line 9 column 6
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 {

Check failure on line 88 in examples/App.tsx

View workflow job for this annotation

GitHub Actions / Lint source files

Static method 'getExample' has too many lines (25). Maximum allowed is 20
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 {

Check failure on line 128 in examples/App.tsx

View workflow job for this annotation

GitHub Actions / Lint source files

Method 'render' has too many lines (31). Maximum allowed is 20
const { currentExample, examplePickerOpen, exampleComponents } = this.state;

return (
<View style={styles.container}>
<View style={{ flex: 1 }}>

Check warning on line 133 in examples/App.tsx

View workflow job for this annotation

GitHub Actions / Lint source files

Inline style: { flex: 1 }
<View style={{ flex: 1 }}>

Check warning on line 134 in examples/App.tsx

View workflow job for this annotation

GitHub Actions / Lint source files

Inline style: { flex: 1 }
<Text>Choose example:</Text>
</View>

<View style={{ flex: 1 }}>

Check warning on line 138 in examples/App.tsx

View workflow job for this annotation

GitHub Actions / Lint source files

Inline style: { flex: 1 }
<DropDownPicker
setValue={this.setCurrentExample}
value={currentExample}
items={exampleComponents}
open={examplePickerOpen}
setOpen={this.setOpen}
/>
</View>
</View>

<View style={{ flex: 3 }}>

Check warning on line 149 in examples/App.tsx

View workflow job for this annotation

GitHub Actions / Lint source files

Inline style: { flex: 3 }
<View style={{ flex: 1 }}>

Check warning on line 150 in examples/App.tsx

View workflow job for this annotation

GitHub Actions / Lint source files

Inline style: { flex: 1 }
<Text>Example:</Text>
</View>

{App.getExample(currentExample)}
</View>
</View>
);
}
}
28 changes: 28 additions & 0 deletions examples/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"expo": {
"name": "examples",
"slug": "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"
}
}
}
Binary file added examples/assets/adaptive-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/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.
Binary file added examples/assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/assets/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions examples/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = function (api) {

Check failure on line 1 in examples/babel.config.js

View workflow job for this annotation

GitHub Actions / Lint source files

Missing @file

Check failure on line 1 in examples/babel.config.js

View workflow job for this annotation

GitHub Actions / Lint source files

Missing return type on function

Check warning on line 1 in examples/babel.config.js

View workflow job for this annotation

GitHub Actions / Lint source files

Unexpected unnamed function
api.cache(true);
return {
presets: ['babel-preset-expo'],
};
};
Loading

0 comments on commit 21b2eb9

Please sign in to comment.