-
Notifications
You must be signed in to change notification settings - Fork 31
feat: Refactor application state handling. #523
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
kinyoklion
merged 12 commits into
feat/client-connection-handling-rework
from
rlamb/sc-251453/refactor-application-state-management
Jul 30, 2024
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d5c0132
feat: Add connection mananger.
kinyoklion 2aa885f
Implement tests.
kinyoklion 2c896b9
Start implementation of the state detector.
kinyoklion 3dd2808
wip
kinyoklion e8e44d3
Make enums backed by string values for easier logging.
kinyoklion f22eb37
Merge branch 'rlamb/sc-251453/add-connection-manager' into rlamb/sc-2…
kinyoklion b54463a
feat: Refactor application state handling.
kinyoklion 3de892d
Merge branch 'feat/client-connection-handling-rework' into rlamb/sc-2…
kinyoklion 359d71d
PR Cleanup
kinyoklion b68e4dd
Add some blank lines.
kinyoklion 7cf3adf
Add not implemented comment.
kinyoklion 9559afd
PR feedback
kinyoklion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,42 @@ | ||
| import { AppState, AppStateStatus } from 'react-native'; | ||
|
|
||
| import { ApplicationState, NetworkState, StateDetector } from './platform/ConnectionManager'; | ||
|
|
||
| function translateAppState(state: AppStateStatus): ApplicationState { | ||
| switch (state) { | ||
| case 'active': | ||
| return ApplicationState.Foreground; | ||
| case 'inactive': | ||
| case 'background': | ||
| case 'extension': | ||
| default: | ||
| return ApplicationState.Background; | ||
| } | ||
| } | ||
|
|
||
| export default class RNStateDetector implements StateDetector { | ||
| private applicationStateListener?: (state: ApplicationState) => void; | ||
| private networkStateListener?: (state: NetworkState) => void; | ||
|
|
||
| constructor() { | ||
| AppState.addEventListener('change', (state: AppStateStatus) => { | ||
| this.applicationStateListener?.(translateAppState(state)); | ||
| }); | ||
| } | ||
|
|
||
| setApplicationStateListener(fn: (state: ApplicationState) => void): void { | ||
| this.applicationStateListener = fn; | ||
| // When you listen provide the current state immediately. | ||
| this.applicationStateListener(translateAppState(AppState.currentState)); | ||
| } | ||
|
|
||
| setNetworkStateListener(fn: (state: NetworkState) => void): void { | ||
| this.networkStateListener = fn; | ||
| // Not implemented. | ||
| } | ||
|
|
||
| stopListening(): void { | ||
| this.applicationStateListener = undefined; | ||
| this.networkStateListener = undefined; | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
114 changes: 0 additions & 114 deletions
114
packages/sdk/react-native/src/provider/useAppState.test.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another problem with this is that the overall desired connection mode would fight with the connection mode determined by the "app state".
If you tell the client to be offline, then you don't expect a foreground transition to set it back online, for example.