Skip to content

Commit

Permalink
Update the lib to 5.x.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Doko-Demo-Doa committed Nov 2, 2021
1 parent 4df799f commit a321ce4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 23 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,20 @@ class MyComponent extends React.Component {
RNShake.removeListener();
}
}
```

// For v5.x.x onwards:
import React from 'react'

export const MyComponent = () => {
React.useEffect(() => {
const subscription = RNShake.addListener(() => {
// Your code here...
})

return () => {
// Your code here...
subscription.remove()
}
}, [])
}
```
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-shake",
"version": "4.0.2",
"version": "5.1.0",
"description": "Detect shake event on Android and iOS",
"homepage": "https://github.com/Doko-Demo-Doa/react-native-shake",
"main": "lib/index.js",
Expand Down Expand Up @@ -36,21 +36,21 @@
"test": "jest"
},
"devDependencies": {
"@babel/core": "^7.13.14",
"@babel/runtime": "^7.13.10",
"@react-native-community/eslint-config": "^2.0.0",
"@types/jest": "^26.0.22",
"@types/react-native": "^0.64.2",
"@types/react-test-renderer": "^17.0.1",
"babel-jest": "^26.6.3",
"eslint": "^7.23.0",
"eslint-plugin-simple-import-sort": "^7.0.0",
"jest": "^26.6.3",
"metro-react-native-babel-preset": "^0.65.2",
"react": "^17.0.2",
"@babel/core": "7.13.14",
"@babel/runtime": "7.13.10",
"@react-native-community/eslint-config": "3.0.1",
"@types/jest": "26.0.22",
"@types/react-native": "0.64.2",
"@types/react-test-renderer": "17.0.1",
"babel-jest": "26.6.3",
"eslint": "7.23.0",
"eslint-plugin-simple-import-sort": "7.0.0",
"jest": "26.6.3",
"metro-react-native-babel-preset": "0.65.2",
"react": "17.0.2",
"react-native": "^0.64.0",
"react-test-renderer": "^17.0.2",
"typescript": "^4.2.3"
"react-test-renderer": "17.0.2",
"typescript": "4.2.3"
},
"peerDependencies": {
"react": "*",
Expand Down
12 changes: 5 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ import { NativeEventEmitter, NativeModules } from 'react-native'
const _eventEmitter = new NativeEventEmitter(NativeModules.RNShakeEvent)

export default {
addListener: (callback: () => void | undefined) =>
_eventEmitter.addListener('ShakeEvent', () => {
addListener: (callback: () => void | undefined) => {
const _subscription = _eventEmitter.addListener('ShakeEvent', () => {
callback?.()
}),
})

removeListener: (callback: () => void | undefined) =>
_eventEmitter.removeListener('ShakeEvent', () => {
callback?.()
}),
return _subscription
},

removeAllListeners: () => _eventEmitter.removeAllListeners('ShakeEvent'),

Expand Down

0 comments on commit a321ce4

Please sign in to comment.