Skip to content
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

[Android] AppState #5152

Closed
wants to merge 1 commit into from

Conversation

skv-headless
Copy link
Contributor

No description provided.

@facebook-github-bot
Copy link
Contributor

By analyzing the blame information on this pull request, we identified @vjeux, @zjj010104 and @mkonicek to be potential reviewers.

@facebook-github-bot facebook-github-bot added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Jan 6, 2016
@mkonicek
Copy link
Contributor

mkonicek commented Jan 6, 2016

We have this module internally and want to open source it, let me compare the implementations.

@mkonicek
Copy link
Contributor

mkonicek commented Jan 6, 2016

Thanks for working on this!

@skv-headless
Copy link
Contributor Author

No problem, thanks for quick response. If I can help you somehow to deliver it faster just let me know.

@mkonicek
Copy link
Contributor

I think we should still keep AppStateIOS.ios.js, AppStateIOS.android.js but introduce a new API AppState.js, similar to what we did with Switch and Alert for example.

Here's the internal module:
Java: https://gist.github.com/mkonicek/039f35748c0a073dd1b5
JS: https://gist.github.com/mkonicek/00c3638a4cf5d9ed8db7

If you can make AppState module that has a single API on Android and iOS that would be amazing. Looks like the AppStateAndroid.js might be redundant? Unfortunately the iOS and Android version were implemented by two different people but we've learned from that and now always think about both platforms at once when adding new APIs.

@mkonicek
Copy link
Contributor

Sorry for the delay on this!

@skv-headless
Copy link
Contributor Author

I'll update pr in few days. Could you please don't release AppStateAndroid? I want to make it same for both platforms as you said.

@facebook-github-bot
Copy link
Contributor

@skv-headless updated the pull request.


var React = require('react-native');
var {
AppState,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

property AppState Property not found in Object.create

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can ignore this lint warning.

@facebook-github-bot
Copy link
Contributor

@skv-headless updated the pull request.

@skv-headless
Copy link
Contributor Author

@mkonicek could you please review?


var React = require('react-native');
var {
AppState,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

property AppState Property not found in Object.create

@satya164
Copy link
Contributor

Since we're introducing a new API, we should use promises instead of callbacks. Refer #4971

@Override
public void onHostPause() {
mAppState = "background";
getReactApplicationContext().getJSModule(RCTDeviceEventEmitter.class)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also have a method sendAppStateEvent?

private void sendAppStateEvent(WritableMap appState) {
  getReactApplicationContext().getJSModule(RCTDeviceEventEmitter.class)
    .emit("appStateDidChange", appState);
}

@mkonicek
Copy link
Contributor

Thanks again for working on it! I'm a bit swamped but will try to review tomorrow.

@facebook-github-bot
Copy link
Contributor

@skv-headless updated the pull request.


var React = require('react-native');
var {
AppState,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

property AppState Property not found in Object.create

@mkonicek
Copy link
Contributor

Is AppState.js a copy of AppStateIOS.ios.js or have you made any changes? Knowing that would make the review easier.

public class AppStateModule extends ReactContextBaseJavaModule
implements LifecycleEventListener {

private String mAppState = "active";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default state should be "uninitialized" as per the internal module: https://gist.github.com/mkonicek/039f35748c0a073dd1b5

What's the rationale for setting it to "active"?


@Override
public void onHostResume() {
mAppState = "active";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkonicek
Copy link
Contributor

Getting close! Very excited!

@skv-headless
Copy link
Contributor Author

AppState.js is a copy of AppStateIOS.ios.js

@mkonicek
Copy link
Contributor

AppState.js is a copy of AppStateIOS.ios.js

Thanks! I guessed that was the case.

@skv-headless
Copy link
Contributor Author

@mkonicek agree with all notes, thank you for review. I'll try to fix tomorrow.

@satya164
Copy link
Contributor

AppState.js is a copy of AppStateIOS.ios.js

If that's the case, can you also get rid of AppState.ios.js, and for platform specific things, add a Platform.OS check?

@skv-headless
Copy link
Contributor Author

@satya164 there is no platform specific code. At first version of PR I deleted AppStateIOS.js module. But @mkonicek asked me to left this component as it is. I think for compatibility with previous version. I copied it to keep them AppState and AppStateIOS independent.

@satya164
Copy link
Contributor

If the APIs are exactly the same, maybe we can just require the AppState file within AppStateIOS and re-export?

@mkonicek
Copy link
Contributor

I like the idea of making AppStateIOS a wrapper around AppState. We can add deprecation warnings and finally delete AppStateIOS a few releases down the line. Let's do that in a separate PR though, this one is already large enough.

@mkonicek
Copy link
Contributor

@skv-headless Cool! Once you address the comments I think we can merge this.

@facebook-github-bot
Copy link
Contributor

@skv-headless updated the pull request.

@skv-headless
Copy link
Contributor Author

@mkonicek updated.
Plan for the future:

  1. deprecation warning to AppStateIOS
  2. android memory event


var React = require('react-native');
var {
AppState,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

property AppState Property not found in Object.create

@mkonicek
Copy link
Contributor

Awesome!

@facebook-github-bot shipit

@facebook-github-bot
Copy link
Contributor

Thanks for importing. If you are an FB employee go to https://our.intern.facebook.com/intern/opensource/github/pull_request/581762778640408/int_phab to review.

@ghost ghost closed this in c2d75d7 Jan 21, 2016
mkonicek pushed a commit that referenced this pull request Jan 29, 2016
Summary: Closes #5152

Reviewed By: svcscm

Differential Revision: D2850250

Pulled By: mkonicek

fb-gh-sync-id: 0b5063fa7121d4e304a70da8573c9ba1d05a757c
@jacygogogo
Copy link

guy can you tell me what is the difference between AppStateIOS and AppState.

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants