Skip to content

Commit

Permalink
chore: add build setup
Browse files Browse the repository at this point in the history
chore: add build setup
  • Loading branch information
nithinpp69 authored Apr 22, 2022
2 parents d80fe32 + 705574c commit a329017
Show file tree
Hide file tree
Showing 19 changed files with 1,487 additions and 2,834 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:
with:
node-version: 12
registry-url: https://registry.npmjs.org
- name: Install dependencies
run: yarn
- name: Release
run: npm publish
env:
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ yarn-error.log

#vscode/

.vscode/
.vscode/

# generated by bob
lib/
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# react-native-switch-toggles
# React Native Switch Toggles 🔥

[![license](https://img.shields.io/github/license/mashape/apistatus.svg)]()
![platforms](https://img.shields.io/badge/platforms-Android%20%7C%20iOS-brightgreen.svg?style=flat&colorB=191A17)
[![Version](https://img.shields.io/npm/v/react-native-switch-toggles.svg)](https://www.npmjs.com/package/react-native-switch-toggles)
[![npm](https://img.shields.io/npm/dt/react-native-switch-toggles.svg)](https://www.npmjs.com/package/react-native-switch-toggles)
[![license](https://img.shields.io/github/license/mashape/apistatus.svg?style=for-the-badge)](https://github.com/nithinpp69/react-native-switch-toggles/blob/main/LICENSE)
![platforms](https://img.shields.io/badge/platforms-Android%20%7C%20iOS-brightgreen.svg?style=for-the-badge&colorB=191A17)
[![Version](https://img.shields.io/npm/v/react-native-switch-toggles.svg?style=for-the-badge)](https://www.npmjs.com/package/react-native-switch-toggles)
[![npm](https://img.shields.io/npm/dt/react-native-switch-toggles.svg?style=for-the-badge)](https://www.npmjs.com/package/react-native-switch-toggles)

A simple and customizable React Native switch component.

## Demo

❤️ [Expo Snack](https://snack.expo.dev/@nithinpp69/react-native-switch-toggles)
## ❤️ [Try on Expo Snack](https://snack.expo.dev/@nithinpp69/react-native-switch-toggles)

![](demo.gif)
![](demo2.gif)
![](examples/demo.gif)
![](examples/demo2.gif)

## Prerequisites

Expand All @@ -27,18 +27,18 @@ Follow [react-native-reanimated-v2](https://docs.swmansion.com/react-native-rean

Supported version: react-native >= 0.59.0

```
```bash
npm install react-native-switch-toggles
```

or

```
```bash
yarn add react-native-switch-toggles
```

## Example
```
```jsx
import Switch from 'react-native-switch-toggles';


Expand All @@ -63,9 +63,9 @@ const [isEnabled, setIsEnabled] = React.useState(false);
/>

```
![](demo.gif)
![](examples/demo.gif)

```
```jsx
import Switch from 'react-native-switch-toggles';


Expand Down Expand Up @@ -190,7 +190,7 @@ const [isEnabled, setIsEnabled] = React.useState(false);
</>

```
![](demo2.gif)
![](examples/demo2.gif)

## Props
| Prop | Description | Type | Default Value | Required |
Expand Down
File renamed without changes
File renamed without changes
3 changes: 0 additions & 3 deletions index.ts

This file was deleted.

21 changes: 0 additions & 21 deletions jest.config.js

This file was deleted.

5 changes: 0 additions & 5 deletions jest/setup.js

This file was deleted.

53 changes: 28 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
{
"name": "react-native-switch-toggles",
"version": "0.0.1",
"version": "1.0.0",
"description": "React Native customizable switch component",
"main": "index",
"main": "lib/commonjs/index",
"module": "lib/module/index",
"types": "lib/typescript/index.d.ts",
"react-native": "src/index",
"files": [
"src",
"lib"
],
"scripts": {
"test": "jest",
"lint": "eslint .",
"lint:fix": "eslint --color --ext .js --fix src/",
"ts": "tsc -d --declarationDir dist/lib --declarationMap --emitDeclarationOnly"
"typescript": "tsc --skipLibCheck --noEmit",
"build": "bob build",
"prepare": "yarn build"
},
"repository": {
"name": "GitHub",
Expand All @@ -32,45 +40,26 @@
"@babel/preset-react": "^7.10.1",
"@babel/runtime": "^7.11.2",
"@react-native-community/eslint-config": "^2.0.0",
"@types/jest": "^27.0.1",
"@types/react-native": "^0.64.13",
"@types/react-test-renderer": "^17.0.1",
"babel-eslint": "^10.1.0",
"babel-jest": "^26.5.0",
"babel-plugin-module-resolver": "^4.1.0",
"babel-plugin-transform-export-extensions": "^6.22.0",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.2",
"eslint": "^7.32.0",
"eslint-plugin-react": "^7.20.0",
"eslint-plugin-react-native": "^3.8.1",
"husky": "^7.0.1",
"jest": "^26.5.0",
"jest-enzyme": "^7.1.2",
"metro-react-native-babel-preset": "^0.63.0",
"react": "16.11.0",
"react-dom": "^17.0.1",
"react-native": "0.62.2",
"react-native-builder-bob": "^0.18.2",
"react-native-gesture-handler": "^1.10.3",
"react-native-reanimated": "^2.2.3",
"react-native-svg": "^12.1.1",
"react-test-renderer": "16.13.1",
"typescript": "^4.4.2"
},
"resolutions": {
"@types/react": "^17"
},
"jest": {
"preset": "react-native",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
]
},
"husky": {
"hooks": {
"pre-commit": "yarn lint"
Expand All @@ -90,5 +79,19 @@
"mobile",
"android",
"ios"
]
],
"react-native-builder-bob": {
"source": "src",
"output": "lib",
"targets": [
"commonjs",
"module",
[
"typescript",
{
"project": "tsconfig.build.json"
}
]
]
}
}
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Switch from './switch';

export default Switch;
16 changes: 8 additions & 8 deletions src/switch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import Animated, {
useSharedValue,
withTiming,
} from "react-native-reanimated";
import Colors from './colors';
import Colors from '../utils/colors';
import styles from './styles';
import { SwitchProps } from './types';
import type { SwitchProps } from './types';

const Switch: React.FC<SwitchProps> = ({
size = 25,
Expand All @@ -26,8 +26,8 @@ const Switch: React.FC<SwitchProps> = ({
renderActiveThumbIcon = () => null,
renderInactiveThumbIcon = () => null,
}) => {
const translateX = useSharedValue(0);
const [switchValue, setSwitchValue] = useState(value);
const translateX: Animated.SharedValue<number> = useSharedValue(0);
const [switchValue, setSwitchValue] = useState<boolean>(value);

useEffect(() => {
setSwitchValue(value);
Expand Down Expand Up @@ -85,7 +85,7 @@ const Switch: React.FC<SwitchProps> = ({
}, [switchValue]);

const onPress = () => {
setSwitchValue(value => !value);
setSwitchValue(_value => !_value);
};

const onIndicatorStyle = useAnimatedStyle(() => {
Expand Down Expand Up @@ -170,20 +170,20 @@ const Switch: React.FC<SwitchProps> = ({
pointerEvents="none"
style={[styles(styleProps).onIndicator, onIndicatorStyle]}
>
{renderOnIndicator()}
{renderOnIndicator?.()}
</Animated.View>
<Animated.View
pointerEvents="none"
style={[styles(styleProps).offIndicator, offIndicatorStyle]}
>
{renderOffIndicator()}
{renderOffIndicator?.()}
</Animated.View>
<Animated.View style={[styles(styleProps).thumb, thumbStyle]}>
<Animated.View pointerEvents="none" style={[styles(styleProps).thumb,thumbActiveStyle]}>
{renderActiveThumbIcon()}
</Animated.View>
<Animated.View pointerEvents="none" style={[styles(styleProps).thumb, thumbInactiveStyle]}>
{renderInactiveThumbIcon()}
{renderInactiveThumbIcon?.()}
</Animated.View>
</Animated.View>
</Animated.View>
Expand Down
9 changes: 8 additions & 1 deletion src/switch/styles.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { StyleSheet } from 'react-native';

const styles = (props) =>
export type StyleProps = {
switchWidth: number;
switchHeight: number;
switchBorderRadius: number;
disabled: boolean;
};

const styles = (props: StyleProps) =>
StyleSheet.create({
switchContainer: {
opacity: props.disabled ? 0.6 : 1,
Expand Down
56 changes: 0 additions & 56 deletions src/switch/types.d.ts

This file was deleted.

Loading

0 comments on commit a329017

Please sign in to comment.