Skip to content

add onPress #106

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

Merged
merged 2 commits into from
Dec 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 5 additions & 8 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
module.exports = {
root: true,
parser: 'babel-eslint',
extends: ['airbnb', 'prettier'],
plugins: ['react-hooks'],
extends: ['airbnb', 'prettier', 'prettier/react'],
plugins: ['react-hooks', 'prettier'],
globals: {
__DEV__: false,
fetch: false
},
rules: {
'import/no-extraneous-dependencies': 0,
'global-require': 0,
'react/prop-types': 0,
'react/prop-types': 'warn',
'react/jsx-closing-bracket-location': 0,
'react/jsx-props-no-spreading': 0,
'react/no-array-index-key': 0,
'react/sort-comp': 0,
'react-hooks/rules-of-hooks': 2,
'react-hooks/exhaustive-deps': 1,
'prefer-const': 0,
'no-underscore-dangle': 0,
'no-plusplus': 0,
'import/prefer-default-export': 0,
'class-methods-use-this': 0,
'react/jsx-filename-extension': 0
'react/jsx-filename-extension': 0,
'react/sort-comp': 0
}
};
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ Headers are one of:

- `Added`, `Changed`, `Removed` or `Fixed`.

## [next]

### Added

- Add `onPress` to `Toast.show` method
- Export `BaseToast` component to allow styling

## [1.3.7]

### Added
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ Toast.show({
topOffset: 30,
bottomOffset: 40,
onShow: () => {},
onHide: () => {}
onHide: () => {},
onPress: () => {}
});
```

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"babel-eslint": "^10.1.0",
"eslint": "^7.10.0",
"eslint-config-airbnb": "^18.0.1",
"eslint-config-prettier": "^6.10.0",
"eslint-config-prettier": "^7.0.0",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-react": "^7.19.0",
Expand All @@ -45,6 +45,7 @@
"prettier": "2.2.1"
},
"dependencies": {
"eslint-plugin-prettier": "^3.2.0",
"prop-types": "^15.7.2"
}
}
23 changes: 16 additions & 7 deletions src/components/base/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function BaseToast({
trailingIcon,
text1,
text2,
onPress,
onLeadingIconPress,
onTrailingIconPress,
style,
Expand All @@ -20,15 +21,19 @@ function BaseToast({
trailingIconStyle,
contentContainerStyle,
text1Style,
text2Style
text2Style,
activeOpacity
}) {
return (
<View style={[styles.base, styles.borderLeft, style]}>
<TouchableOpacity
style={[styles.base, styles.borderLeft, style]}
onPress={onPress}
activeOpacity={activeOpacity}>
{leadingIcon && (
<TouchableOpacity
style={[styles.leadingIconContainer, leadingIconContainerStyle]}
onPress={onLeadingIconPress}
activeOpacity={1}>
activeOpacity={activeOpacity}>
<Icon
style={[styles.leadingIcon, leadingIconStyle]}
source={leadingIcon}
Expand Down Expand Up @@ -57,14 +62,14 @@ function BaseToast({
<TouchableOpacity
style={[styles.trailingIconContainer, trailingIconContainerStyle]}
onPress={onTrailingIconPress}
activeOpacity={1}>
activeOpacity={activeOpacity}>
<Icon
style={[styles.trailingIcon, trailingIconStyle]}
source={trailingIcon}
/>
</TouchableOpacity>
)}
</View>
</TouchableOpacity>
);
}

Expand All @@ -75,6 +80,7 @@ BaseToast.propTypes = {
trailingIcon: Icon.propTypes.source,
text1: PropTypes.string,
text2: PropTypes.string,
onPress: PropTypes.func,
onTrailingIconPress: PropTypes.func,
onLeadingIconPress: PropTypes.func,
style: ViewPropTypes.style,
Expand All @@ -84,14 +90,16 @@ BaseToast.propTypes = {
trailingIconStyle: ViewPropTypes.style,
contentContainerStyle: ViewPropTypes.style,
text1Style: ViewPropTypes.style,
text2Style: ViewPropTypes.style
text2Style: ViewPropTypes.style,
activeOpacity: PropTypes.number
};

BaseToast.defaultProps = {
leadingIcon: undefined,
trailingIcon: icons.close,
text1: undefined,
text2: undefined,
onPress: undefined,
onLeadingIconPress: undefined,
onTrailingIconPress: undefined,
style: undefined,
Expand All @@ -101,7 +109,8 @@ BaseToast.defaultProps = {
trailingIconStyle: undefined,
contentContainerStyle: undefined,
text1Style: undefined,
text2Style: undefined
text2Style: undefined,
activeOpacity: 0.8
};

export default BaseToast;
18 changes: 10 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import styles from './styles';
const FRICTION = 8;

const defaultComponentsConfig = {
success: ({ hide, text1, text2 }) => (
<SuccessToast onTrailingIconPress={hide} text1={text1} text2={text2} />
success: ({ hide, ...rest }) => (
<SuccessToast {...rest} onTrailingIconPress={hide} />
),
error: ({ hide, text1, text2 }) => (
<ErrorToast onTrailingIconPress={hide} text1={text1} text2={text2} />
error: ({ hide, ...rest }) => (
<ErrorToast {...rest} onTrailingIconPress={hide} />
),
info: ({ hide, text1, text2 }) => (
<InfoToast onTrailingIconPress={hide} text1={text1} text2={text2} />
info: ({ hide, ...rest }) => (
<InfoToast {...rest} onTrailingIconPress={hide} />
)
};

Expand Down Expand Up @@ -47,6 +47,7 @@ const getInitialState = (props) => {
text1: undefined,
text2: undefined,

onPress: undefined,
onShow,
onHide
};
Expand Down Expand Up @@ -98,7 +99,7 @@ class Toast extends Component {
};

this.panResponder = PanResponder.create({
onStartShouldSetPanResponder: () => true,
onMoveShouldSetPanResponder: () => true,
onPanResponderMove: (event, gesture) => {
this._animateMovement(gesture);
},
Expand Down Expand Up @@ -272,7 +273,8 @@ class Toast extends Component {
'text1',
'text2',
'hide',
'show'
'show',
'onPress'
]
}),
props: { ...customProps },
Expand Down
5 changes: 2 additions & 3 deletions src/utils/obj.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
const includeKeys = ({ obj = {}, keys = [] }) => {
return Object.keys(obj).reduce((acc, key) => {
const includeKeys = ({ obj = {}, keys = [] }) =>
Object.keys(obj).reduce((acc, key) => {
if (keys.includes(key)) {
acc[key] = obj[key];
}
return acc;
}, {});
};

export { includeKeys };
34 changes: 23 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -627,12 +627,10 @@ eslint-config-airbnb@^18.0.1:
object.assign "^4.1.2"
object.entries "^1.1.2"

eslint-config-prettier@^6.10.0:
version "6.15.0"
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-6.15.0.tgz#7f93f6cb7d45a92f1537a70ecc06366e1ac6fed9"
integrity sha512-a1+kOYLR8wMGustcgAjdydMsQ2A/2ipRPwRKUmfYaSxc9ZPcrku080Ctl6zrZzZNs/U82MjSv+qKREkoq3bJaw==
dependencies:
get-stdin "^6.0.0"
eslint-config-prettier@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-7.0.0.tgz#c1ae4106f74e6c0357f44adb076771d032ac0e97"
integrity sha512-8Y8lGLVPPZdaNA7JXqnvETVC7IiVRgAP6afQu9gOQRn90YY3otMNh+x7Vr2vMePQntF+5erdSUBqSzCmU/AxaQ==

eslint-import-resolver-node@^0.3.4:
version "0.3.4"
Expand Down Expand Up @@ -686,6 +684,13 @@ eslint-plugin-jsx-a11y@^6.2.3:
jsx-ast-utils "^3.1.0"
language-tags "^1.0.5"

eslint-plugin-prettier@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-3.2.0.tgz#af391b2226fa0e15c96f36c733f6e9035dbd952c"
integrity sha512-kOUSJnFjAUFKwVxuzy6sA5yyMx6+o9ino4gCdShzBNx4eyFRudWRYKCFolKjoM40PEiuU6Cn7wBLfq3WsGg7qg==
dependencies:
prettier-linter-helpers "^1.0.0"

eslint-plugin-react-hooks@^4.0.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-4.2.0.tgz#8c229c268d468956334c943bb45fc860280f5556"
Expand Down Expand Up @@ -852,6 +857,11 @@ fast-deep-equal@^3.1.1:
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525"
integrity sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==

fast-diff@^1.1.2:
version "1.2.0"
resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.2.0.tgz#73ee11982d86caaf7959828d519cfe927fac5f03"
integrity sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==

fast-json-stable-stringify@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz#d5142c0caee6b1189f87d3a76111064f86c8bbf2"
Expand Down Expand Up @@ -941,11 +951,6 @@ get-own-enumerable-property-symbols@^3.0.0:
resolved "https://registry.yarnpkg.com/get-own-enumerable-property-symbols/-/get-own-enumerable-property-symbols-3.0.1.tgz#6f7764f88ea11e0b514bd9bd860a132259992ca4"
integrity sha512-09/VS4iek66Dh2bctjRkowueRJbY1JDGR1L/zRxO1Qk8Uxs6PnqaNSqalpizPT+CDjre3hnEsuzvhgomz9qYrA==

get-stdin@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-6.0.0.tgz#9e09bf712b360ab9225e812048f71fde9c89657b"
integrity sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==

get-stdin@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-7.0.0.tgz#8d5de98f15171a125c5e516643c7a6d0ea8a96f6"
Expand Down Expand Up @@ -1726,6 +1731,13 @@ prelude-ls@^1.2.1:
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396"
integrity sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==

prettier-linter-helpers@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz#d23d41fe1375646de2d0104d3454a3008802cf7b"
integrity sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==
dependencies:
fast-diff "^1.1.2"

[email protected]:
version "2.2.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.2.1.tgz#795a1a78dd52f073da0cd42b21f9c91381923ff5"
Expand Down