Skip to content

Commit

Permalink
update scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
calintamas committed Oct 1, 2020
1 parent 21155ea commit 2af7fa0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 29 deletions.
50 changes: 27 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,42 @@
An animated toast message component for React Native that can be called imperatively.

## Install

```
yarn add react-native-toast-message
```

![ToastSuccess](success-toast.gif)

## Usage

```js
// root.jsx
// Add the component your app root
import Toast from 'react-native-toast-message'
import Toast from 'react-native-toast-message';

const Root = () => {
return (
<Toast ref={(ref) => Toast.setRef(ref)} />
)
}
return <Toast ref={(ref) => Toast.setRef(ref)} />;
};

export default Root
export default Root;
```

Then use it anywhere in your app like this

```js
import Toast from 'react-native-toast-message'
import Toast from 'react-native-toast-message';

Toast.show({
text1: 'Hello',
text2: 'This is some something 👋'
})
});
```

## API

### `show(options = {})`

When calling the `show` method, you can use the following `options` to suit your needs. Everything is optional, unless specified otherwise.

The usage of `|` below, means that only one of the values show should be used.
Expand All @@ -56,14 +60,15 @@ Toast.show({
bottomOffset: 40,
onShow: () => {},
onHide: () => {}
})
});
```

### `hide(options = {})`

```js
Toast.hide({
onHide: () => {}
})
});
```

## Customizing the toast types
Expand All @@ -72,33 +77,32 @@ If you want to add custom types - or overwrite the existing ones - you can add a

```js
// root.jsx
import Toast from 'react-native-toast-message'
import Toast from 'react-native-toast-message';

const toastConfig = {
'success': (internalState) => (
success: (internalState) => (
<View style={{ height: 60, width: '100%', backgroundColor: 'pink' }}>
<Text>{internalState.text1}</Text>
</View>
</View>
),
'error': () => {},
'info': () => {},
'any_custom_type': () => {}
}
error: () => {},
info: () => {},
any_custom_type: () => {}
};

const Root = () => {
return (
<Toast config={toastConfig} ref={(ref) => Toast.setRef(ref)} />
)
}
return <Toast config={toastConfig} ref={(ref) => Toast.setRef(ref)} />;
};

export default Root
export default Root;
```

Then just use the library as before

```js
Toast.show({ type: 'any_custom_type' })
Toast.show({ type: 'any_custom_type' });
```

## Credits

The icons for the default `success`, `error` and `info` types are made by [Pixel perfect](https://www.flaticon.com/authors/pixel-perfect) from [flaticon.com](www.flaticon.com).
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
"main": "index.js",
"scripts": {
"hooks:install": "node ./node_modules/husky/bin/install",
"lint": "eslint . --ext=jsx --ext=js",
"lint-staged": "lint-staged"
"lint": "./node_modules/.bin/eslint . --ext=jsx --ext=js",
"lint-staged": "./node_modules/.bin/lint-staged",
"prettier": "./node_modules/.bin/prettier . --write"
},
"lint-staged": {
"**/*.js": [
Expand Down
8 changes: 4 additions & 4 deletions src/components/base/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ const BaseToast = (props) => {

<View style={styles.contentContainer}>
<View style={styles.body}>
{text1 !== undefined &&
{text1 !== undefined && (
<View>
<Text style={styles.text1} numberOfLines={1}>
{text1}
</Text>
</View>
}
{text2 !== undefined &&
)}
{text2 !== undefined && (
<View>
<Text style={styles.text2} numberOfLines={2}>
{text2}
</Text>
</View>
}
)}
</View>
</View>

Expand Down

0 comments on commit 2af7fa0

Please sign in to comment.