Skip to content

Commit

Permalink
feat: Remove deprecated Linking.removeEventListener
Browse files Browse the repository at this point in the history
Linking.removeEventListener has been removed from react-native 0.71.
We need to call remove() on the subcription returned by
Linking.addEventListener().

Still compatible with react-native 0.66.
  • Loading branch information
zatteo committed Apr 5, 2024
1 parent d6a21c0 commit 9544207
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions packages/cozy-client/src/authentication/mobile.native.js
Expand Up @@ -24,6 +24,8 @@ const USER_CANCELED = 'USER_CANCELED'

export const authenticateWithReactNativeInAppBrowser = async url => {
return new Promise((resolve, reject) => {
let linkingSubscription = null

InAppBrowser.open(url, {
// iOS Properties
readerMode: false,
Expand Down Expand Up @@ -53,9 +55,6 @@ export const authenticateWithReactNativeInAppBrowser = async url => {
reject(USER_CANCELED)
}
})
const removeListener = () => {
Linking.removeEventListener('url', linkListener)
}

const linkListener = ({ url }) => {
let sanitizedUrl = url
Expand All @@ -79,14 +78,14 @@ export const authenticateWithReactNativeInAppBrowser = async url => {
}
}
resolve(sanitizedUrl)
removeListener()
linkingSubscription.remove()
InAppBrowser.close()
} else if (closeSignal) {
reject(USER_CANCELED)
}
}

Linking.addEventListener('url', linkListener)
linkingSubscription = Linking.addEventListener('url', linkListener)
})
}

Expand Down

0 comments on commit 9544207

Please sign in to comment.