-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38093 from ikevin127/fix/36645
FIX: Performance and heat issues on the 'Troubleshoot' page
- Loading branch information
Showing
4 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react'; | ||
import type {AppStateStatus} from 'react-native'; | ||
import {AppState} from 'react-native'; | ||
import type AppStateType from './types'; | ||
|
||
function useAppState() { | ||
const [appState, setAppState] = React.useState<AppStateType>({ | ||
isForeground: AppState.currentState === 'active', | ||
isInactive: AppState.currentState === 'inactive', | ||
isBackground: AppState.currentState === 'background', | ||
}); | ||
|
||
React.useEffect(() => { | ||
function handleAppStateChange(nextAppState: AppStateStatus) { | ||
setAppState({ | ||
isForeground: nextAppState === 'active', | ||
isInactive: nextAppState === 'inactive', | ||
isBackground: nextAppState === 'background', | ||
}); | ||
} | ||
const subscription = AppState.addEventListener('change', handleAppStateChange); | ||
return () => subscription.remove(); | ||
}, []); | ||
|
||
return appState; | ||
} | ||
|
||
export default useAppState; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type AppStateType from './types'; | ||
|
||
function useAppState(): AppStateType { | ||
// Since there's no AppState in web, we'll always return isForeground as true | ||
return {isForeground: true, isInactive: false, isBackground: false}; | ||
} | ||
|
||
export default useAppState; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
type AppStateType = { | ||
isForeground: boolean; | ||
isInactive: boolean; | ||
isBackground: boolean; | ||
}; | ||
|
||
export default AppStateType; |