Skip to content

Commit

Permalink
🏷️ Update react native type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
williamchong committed Oct 16, 2023
1 parent 895f628 commit 0041ef1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
10 changes: 8 additions & 2 deletions app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as React from "react"
import {
Alert,
AppRegistry,
EmitterSubscription,
Linking,
Platform,
} from "react-native"
Expand Down Expand Up @@ -49,6 +50,8 @@ export class App extends React.Component<{}, AppState> {

initTimer?: number

openUrlHandler?: EmitterSubscription

/**
* When the component is mounted. This happens asynchronously and simply
* re-renders when we're good to go.
Expand All @@ -75,7 +78,7 @@ export class App extends React.Component<{}, AppState> {

this.state.rootStore?.userStore.checkTrackingStatus()

Linking.addEventListener('url', this._onOpenURL)
this.openUrlHandler = Linking.addEventListener('url', this._onOpenURL)
try {
const url = await Linking.getInitialURL()
if (!url) return
Expand All @@ -86,7 +89,10 @@ export class App extends React.Component<{}, AppState> {
}

componentWillUnmount() {
Linking.removeEventListener('url', this._onOpenURL)
if (this.openUrlHandler) {
this.openUrlHandler.remove()
this.openUrlHandler = null
}
}

startInitTimer = () => {
Expand Down
10 changes: 8 additions & 2 deletions app/screens/reader-screen/reader-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from "react"
import {
AppState,
AppStateStatus,
NativeEventSubscription,
} from "react-native"
import { inject } from "mobx-react"
import styled from "styled-components/native"
Expand Down Expand Up @@ -29,6 +30,8 @@ const Screen = styled(ScreenBase)`
export class ReaderScreen extends React.Component<Props, {}> {
appState = AppState.currentState

appStateChangeHandler?: NativeEventSubscription

superLikeScreen = React.createRef<MySuperLikeScreenBase>()

state = {
Expand All @@ -37,11 +40,14 @@ export class ReaderScreen extends React.Component<Props, {}> {

componentDidMount() {
this.props.contentBookmarksListStore.fetch()
AppState.addEventListener("change", this.handleAppStateChange)
this.appStateChangeHandler = AppState.addEventListener("change", this.handleAppStateChange)
}

componentWillUnmount() {
AppState.removeEventListener("change", this.handleAppStateChange)
if (this.appStateChangeHandler) {
this.appStateChangeHandler.remove()
this.appStateChangeHandler = null
}
}

private handleAppStateChange = (nextAppState: AppStateStatus) => {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@
"@types/jest": "24.0.16",
"@types/jsonwebtoken": "^9.0.0",
"@types/ramda": "0.26.18",
"@types/react": "18.0.0",
"@types/react-native": "^0.69.0",
"@types/react": "18.0.38",
"@types/react-native": "^0.70.0",
"@types/react-native-share-extension": "^2.0.1",
"@types/react-test-renderer": "16.8.3",
"@types/styled-components": "^5.1.9",
Expand Down
19 changes: 14 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4336,10 +4336,10 @@
dependencies:
"@types/react" "*"

"@types/react-native@^0.69.0":
version "0.69.21"
resolved "https://registry.yarnpkg.com/@types/react-native/-/react-native-0.69.21.tgz#50180a7531310df3bb71fda4d1822bca42039ac8"
integrity sha512-D8WTR5gmrdwv95nxzjRdrYYRENv9UEP/MJemHWSBK10FYi2+qqpLq9D3W2pJNJCA6xUzIAQwcUrAsWbwQTadOA==
"@types/react-native@^0.70.0":
version "0.70.14"
resolved "https://registry.yarnpkg.com/@types/react-native/-/react-native-0.70.14.tgz#8619b8c94296f6456c5362d74a3d1b4fad3f54ab"
integrity sha512-Kwc+BYBrnDqvacNxKp1UtcZJnJJnTih2NYmi/ieAKlHdxEPN6sYMwmIwgHdoLHggvml6bf3DYRaH2jt+gzaLjw==
dependencies:
"@types/react" "*"

Expand All @@ -4364,7 +4364,7 @@
dependencies:
"@types/react" "*"

"@types/react@*", "@types/[email protected]":
"@types/react@*":
version "18.0.0"
resolved "https://registry.yarnpkg.com/@types/react/-/react-18.0.0.tgz#4be8aa3a2d04afc3ac2cc1ca43d39b0bd412890c"
integrity sha512-7+K7zEQYu7NzOwQGLR91KwWXXDzmTFODRVizJyIALf6RfLv2GDpqpknX64pvRVILXCpXi7O/pua8NGk44dLvJw==
Expand All @@ -4373,6 +4373,15 @@
"@types/scheduler" "*"
csstype "^3.0.2"

"@types/[email protected]":
version "18.0.38"
resolved "https://registry.yarnpkg.com/@types/react/-/react-18.0.38.tgz#02a23bef8848b360a0d1dceef4432c15c21c600c"
integrity sha512-ExsidLLSzYj4cvaQjGnQCk4HFfVT9+EZ9XZsQ8Hsrcn8QNgXtpZ3m9vSIC2MWtx7jHictK6wYhQgGh6ic58oOw==
dependencies:
"@types/prop-types" "*"
"@types/scheduler" "*"
csstype "^3.0.2"

"@types/scheduler@*":
version "0.16.3"
resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.3.tgz#cef09e3ec9af1d63d2a6cc5b383a737e24e6dcf5"
Expand Down

0 comments on commit 0041ef1

Please sign in to comment.