{"action":"created","comment":{"url":"https://api.github.com/repos/facebook/react-native/pulls/comments/101870647","pull_request_review_id":22617093,"id":101870647,"diff_hunk":"@@ -0,0 +1,191 @@\n+package com.facebook.react;\n+\n+import android.app.Activity;\n+import android.content.Intent;\n+import android.net.Uri;\n+import android.os.Build;\n+import android.os.Bundle;\n+import android.provider.Settings;\n+import android.view.KeyEvent;\n+import android.widget.Toast;\n+\n+import com.facebook.common.logging.FLog;\n+import com.facebook.infer.annotation.Assertions;\n+import com.facebook.react.common.ReactConstants;\n+import com.facebook.react.devsupport.DoubleTapReloadRecognizer;\n+import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;\n+\n+import javax.annotation.Nullable;\n+\n+/**\n+ * A delegate for handling React Application support. This delegate is unaware whether it is used in\n+ * an {@link Activity} or a {@link android.app.Fragment}.\n+ */\n+public class ReactDelegate {\n+\n+  public final int REQUEST_OVERLAY_PERMISSION_CODE = 1111;\n+  private static final String REDBOX_PERMISSION_MESSAGE =\n+    \"Overlay permissions need to be granted in order for react native apps to run in dev mode.\";\n+  private static final String REDBOX_PERMISSION_GRANTED_MESSAGE =\n+    \"Overlay permissions have been granted.\";\n+\n+\n+  private final Activity mActivity;\n+  private ReactRootView mReactRootView;\n+\n+\n+  @Nullable\n+  private final String mMainComponentName;\n+\n+  @Nullable\n+  private Bundle mLaunchOptions;\n+\n+  @Nullable\n+  private DoubleTapReloadRecognizer mDoubleTapReloadRecognizer;\n+\n+\n+  public ReactDelegate(Activity activity, String appKey, Bundle launchOptions) {\n+    mActivity = activity;\n+    mMainComponentName = appKey;\n+    mLaunchOptions = launchOptions;\n+    mDoubleTapReloadRecognizer = new DoubleTapReloadRecognizer();\n+  }\n+\n+  public void onHostResume() {\n+    if (getReactNativeHost().hasInstance()) {\n+      if (mActivity instanceof DefaultHardwareBackBtnHandler) {","path":"ReactAndroid/src/main/java/com/facebook/react/ReactDelegate.java","position":56,"original_position":56,"commit_id":"b089982ebe9cec0e86a71bf4986c783ac5355e37","original_commit_id":"99028badc22435725feb6ede141a38420b032fd5","user":{"login":"jpshelley","id":2798846,"avatar_url":"https://avatars.githubusercontent.com/u/2798846?v=3","gravatar_id":"","url":"https://api.github.com/users/jpshelley","html_url":"https://github.com/jpshelley","followers_url":"https://api.github.com/users/jpshelley/followers","following_url":"https://api.github.com/users/jpshelley/following{/other_user}","gists_url":"https://api.github.com/users/jpshelley/gists{/gist_id}","starred_url":"https://api.github.com/users/jpshelley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jpshelley/subscriptions","organizations_url":"https://api.github.com/users/jpshelley/orgs","repos_url":"https://api.github.com/users/jpshelley/repos","events_url":"https://api.github.com/users/jpshelley/events{/privacy}","received_events_url":"https://api.github.com/users/jpshelley/received_events","type":"User","site_admin":false},"body":"@serj-lotutovici So I updated the code a bit in https://github.com/facebook/react-native/pull/12199/commits/b089982ebe9cec0e86a71bf4986c783ac5355e37\r\n\r\nAfter messing with fragment navigations stacks this week, it seemed easier to allow the Activity to handle the back navigation. If the Fragment handled the back button handler, it ended up getting stuck in a loop, or it wasn't able to safely call the `super.onBackPressed()` like I was hoping for. I'm open to suggestions but this is the conclusion I came to.\r\n\r\nThis will be shown via documentation for sure, but I'll work on documentation if/when we get this PR \"approved\" and the idea is solidified.","created_at":"2017-02-17T23:50:12Z","updated_at":"2017-02-17T23:50:12Z","html_url":"https://github.com/facebook/react-native/pull/12199#discussion_r101870647","pull_request_url":"https://api.github.com/repos/facebook/react-native/pulls/12199","_links":{"self":{"href":"https://api.github.com/repos/facebook/react-native/pulls/comments/101870647"},"html":{"href":"https://github.com/facebook/react-native/pull/12199#discussion_r101870647"},"pull_request":{"href":"https://api.github.com/repos/facebook/react-native/pulls/12199"}}},"pull_request":{"url":"https://api.github.com/repos/facebook/react-native/pulls/12199","id":104603146,"html_url":"https://github.com/facebook/react-native/pull/12199","diff_url":"https://github.com/facebook/react-native/pull/12199.diff","patch_url":"https://github.com/facebook/react-native/pull/12199.patch","issue_url":"https://api.github.com/repos/facebook/react-native/issues/12199","number":12199,"state":"open","locked":false,"title":"Android - Create the ReactFragment","user":{"login":"jpshelley","id":2798846,"avatar_url":"https://avatars.githubusercontent.com/u/2798846?v=3","gravatar_id":"","url":"https://api.github.com/users/jpshelley","html_url":"https://github.com/jpshelley","followers_url":"https://api.github.com/users/jpshelley/followers","following_url":"https://api.github.com/users/jpshelley/following{/other_user}","gists_url":"https://api.github.com/users/jpshelley/gists{/gist_id}","starred_url":"https://api.github.com/users/jpshelley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jpshelley/subscriptions","organizations_url":"https://api.github.com/users/jpshelley/orgs","repos_url":"https://api.github.com/users/jpshelley/repos","events_url":"https://api.github.com/users/jpshelley/events{/privacy}","received_events_url":"https://api.github.com/users/jpshelley/received_events","type":"User","site_admin":false},"body":"## Overview\r\n\r\nReact Native on Android has currently been focused and targeted at using an [Activity](https://developer.android.com/reference/android/app/Activity.html) for its main form of instantiation.\r\n\r\nWhile this has probably worked for most companies and developers, you lose some of the modularity of a more cohesive application when working in a \"brown-field\" project that is currently native. This hurts more companies that are looking to adopt React Native and slowly implement it in a fully native application.\r\n\r\nA lot of developers follow Android's guidelines of using Fragments in their projects, even if it is a debated subject in the Android community, and this addition will allow others to embrace React Native more freely. (I even assume it could help with managing navigation state in applications that contain a decent amount of Native code and would be appreciated in those projects. Such as sharing the Toolbar, TabBar, ViewPager, etc in Native Android) \r\n\r\nEven with this addition, a developer will still need to host the fragment in an activity, but now that activity can contain native logic like a Drawer, Tabs, ViewPager, etc.\r\n\r\n**Test plan (required)**\r\n* We have been using this class at Hudl for over a couple of months and have found it valuable.\r\n* If the community agrees on the addition, I can add documentation to the Android sections to include notes about the potential of this Fragment.\r\n* If the community agrees on the addition, I can update one or more of the examples in the `/Examples` folder and make use of the Fragment, or even create a new example that uses a native layout manager like Drawer, Tabs, Viewpager, etc)\r\n\r\nMake sure tests pass on both Travis and Circle CI.\r\n\r\n_To Note:_\r\n* There is also talk of using React Native inside Android Fragment's without any legit documentation, this could help remedy some of that with more documentation included in this PR https://facebook.github.io/react-native/releases/0.26/docs/embedded-app-android.html#sharing-a-reactinstance-across-multiple-activities-fragments-in-your-app\r\n* Others have also requested something similar and have a half-baked solution as well http://stackoverflow.com/questions/35221447/react-native-inside-a-fragment","created_at":"2017-02-03T20:10:45Z","updated_at":"2017-02-17T23:50:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ecf00cc2ed2f52ca464aed5f6455661f6cb9f432","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/facebook/react-native/pulls/12199/commits","review_comments_url":"https://api.github.com/repos/facebook/react-native/pulls/12199/comments","review_comment_url":"https://api.github.com/repos/facebook/react-native/pulls/comments{/number}","comments_url":"https://api.github.com/repos/facebook/react-native/issues/12199/comments","statuses_url":"https://api.github.com/repos/facebook/react-native/statuses/b089982ebe9cec0e86a71bf4986c783ac5355e37","head":{"label":"jpshelley:Android-CreateReactFragment","ref":"Android-CreateReactFragment","sha":"b089982ebe9cec0e86a71bf4986c783ac5355e37","user":{"login":"jpshelley","id":2798846,"avatar_url":"https://avatars.githubusercontent.com/u/2798846?v=3","gravatar_id":"","url":"https://api.github.com/users/jpshelley","html_url":"https://github.com/jpshelley","followers_url":"https://api.github.com/users/jpshelley/followers","following_url":"https://api.github.com/users/jpshelley/following{/other_user}","gists_url":"https://api.github.com/users/jpshelley/gists{/gist_id}","starred_url":"https://api.github.com/users/jpshelley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jpshelley/subscriptions","organizations_url":"https://api.github.com/users/jpshelley/orgs","repos_url":"https://api.github.com/users/jpshelley/repos","events_url":"https://api.github.com/users/jpshelley/events{/privacy}","received_events_url":"https://api.github.com/users/jpshelley/received_events","type":"User","site_admin":false},"repo":{"id":75688503,"name":"react-native","full_name":"jpshelley/react-native","owner":{"login":"jpshelley","id":2798846,"avatar_url":"https://avatars.githubusercontent.com/u/2798846?v=3","gravatar_id":"","url":"https://api.github.com/users/jpshelley","html_url":"https://github.com/jpshelley","followers_url":"https://api.github.com/users/jpshelley/followers","following_url":"https://api.github.com/users/jpshelley/following{/other_user}","gists_url":"https://api.github.com/users/jpshelley/gists{/gist_id}","starred_url":"https://api.github.com/users/jpshelley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jpshelley/subscriptions","organizations_url":"https://api.github.com/users/jpshelley/orgs","repos_url":"https://api.github.com/users/jpshelley/repos","events_url":"https://api.github.com/users/jpshelley/events{/privacy}","received_events_url":"https://api.github.com/users/jpshelley/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jpshelley/react-native","description":"A framework for building native apps with React.","fork":true,"url":"https://api.github.com/repos/jpshelley/react-native","forks_url":"https://api.github.com/repos/jpshelley/react-native/forks","keys_url":"https://api.github.com/repos/jpshelley/react-native/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jpshelley/react-native/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jpshelley/react-native/teams","hooks_url":"https://api.github.com/repos/jpshelley/react-native/hooks","issue_events_url":"https://api.github.com/repos/jpshelley/react-native/issues/events{/number}","events_url":"https://api.github.com/repos/jpshelley/react-native/events","assignees_url":"https://api.github.com/repos/jpshelley/react-native/assignees{/user}","branches_url":"https://api.github.com/repos/jpshelley/react-native/branches{/branch}","tags_url":"https://api.github.com/repos/jpshelley/react-native/tags","blobs_url":"https://api.github.com/repos/jpshelley/react-native/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jpshelley/react-native/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jpshelley/react-native/git/refs{/sha}","trees_url":"https://api.github.com/repos/jpshelley/react-native/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jpshelley/react-native/statuses/{sha}","languages_url":"https://api.github.com/repos/jpshelley/react-native/languages","stargazers_url":"https://api.github.com/repos/jpshelley/react-native/stargazers","contributors_url":"https://api.github.com/repos/jpshelley/react-native/contributors","subscribers_url":"https://api.github.com/repos/jpshelley/react-native/subscribers","subscription_url":"https://api.github.com/repos/jpshelley/react-native/subscription","commits_url":"https://api.github.com/repos/jpshelley/react-native/commits{/sha}","git_commits_url":"https://api.github.com/repos/jpshelley/react-native/git/commits{/sha}","comments_url":"https://api.github.com/repos/jpshelley/react-native/comments{/number}","issue_comment_url":"https://api.github.com/repos/jpshelley/react-native/issues/comments{/number}","contents_url":"https://api.github.com/repos/jpshelley/react-native/contents/{+path}","compare_url":"https://api.github.com/repos/jpshelley/react-native/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jpshelley/react-native/merges","archive_url":"https://api.github.com/repos/jpshelley/react-native/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jpshelley/react-native/downloads","issues_url":"https://api.github.com/repos/jpshelley/react-native/issues{/number}","pulls_url":"https://api.github.com/repos/jpshelley/react-native/pulls{/number}","milestones_url":"https://api.github.com/repos/jpshelley/react-native/milestones{/number}","notifications_url":"https://api.github.com/repos/jpshelley/react-native/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jpshelley/react-native/labels{/name}","releases_url":"https://api.github.com/repos/jpshelley/react-native/releases{/id}","deployments_url":"https://api.github.com/repos/jpshelley/react-native/deployments","created_at":"2016-12-06T02:55:57Z","updated_at":"2016-12-06T02:56:08Z","pushed_at":"2017-02-17T23:47:32Z","git_url":"git://github.com/jpshelley/react-native.git","ssh_url":"git@github.com:jpshelley/react-native.git","clone_url":"https://github.com/jpshelley/react-native.git","svn_url":"https://github.com/jpshelley/react-native","homepage":"http://facebook.github.io/react-native/","size":112238,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"facebook:master","ref":"master","sha":"e81258a15b076d2805912fae11351311c412ad5e","user":{"login":"facebook","id":69631,"avatar_url":"https://avatars.githubusercontent.com/u/69631?v=3","gravatar_id":"","url":"https://api.github.com/users/facebook","html_url":"https://github.com/facebook","followers_url":"https://api.github.com/users/facebook/followers","following_url":"https://api.github.com/users/facebook/following{/other_user}","gists_url":"https://api.github.com/users/facebook/gists{/gist_id}","starred_url":"https://api.github.com/users/facebook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebook/subscriptions","organizations_url":"https://api.github.com/users/facebook/orgs","repos_url":"https://api.github.com/users/facebook/repos","events_url":"https://api.github.com/users/facebook/events{/privacy}","received_events_url":"https://api.github.com/users/facebook/received_events","type":"Organization","site_admin":false},"repo":{"id":29028775,"name":"react-native","full_name":"facebook/react-native","owner":{"login":"facebook","id":69631,"avatar_url":"https://avatars.githubusercontent.com/u/69631?v=3","gravatar_id":"","url":"https://api.github.com/users/facebook","html_url":"https://github.com/facebook","followers_url":"https://api.github.com/users/facebook/followers","following_url":"https://api.github.com/users/facebook/following{/other_user}","gists_url":"https://api.github.com/users/facebook/gists{/gist_id}","starred_url":"https://api.github.com/users/facebook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebook/subscriptions","organizations_url":"https://api.github.com/users/facebook/orgs","repos_url":"https://api.github.com/users/facebook/repos","events_url":"https://api.github.com/users/facebook/events{/privacy}","received_events_url":"https://api.github.com/users/facebook/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/facebook/react-native","description":"A framework for building native apps with React.","fork":false,"url":"https://api.github.com/repos/facebook/react-native","forks_url":"https://api.github.com/repos/facebook/react-native/forks","keys_url":"https://api.github.com/repos/facebook/react-native/keys{/key_id}","collaborators_url":"https://api.github.com/repos/facebook/react-native/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/facebook/react-native/teams","hooks_url":"https://api.github.com/repos/facebook/react-native/hooks","issue_events_url":"https://api.github.com/repos/facebook/react-native/issues/events{/number}","events_url":"https://api.github.com/repos/facebook/react-native/events","assignees_url":"https://api.github.com/repos/facebook/react-native/assignees{/user}","branches_url":"https://api.github.com/repos/facebook/react-native/branches{/branch}","tags_url":"https://api.github.com/repos/facebook/react-native/tags","blobs_url":"https://api.github.com/repos/facebook/react-native/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/facebook/react-native/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/facebook/react-native/git/refs{/sha}","trees_url":"https://api.github.com/repos/facebook/react-native/git/trees{/sha}","statuses_url":"https://api.github.com/repos/facebook/react-native/statuses/{sha}","languages_url":"https://api.github.com/repos/facebook/react-native/languages","stargazers_url":"https://api.github.com/repos/facebook/react-native/stargazers","contributors_url":"https://api.github.com/repos/facebook/react-native/contributors","subscribers_url":"https://api.github.com/repos/facebook/react-native/subscribers","subscription_url":"https://api.github.com/repos/facebook/react-native/subscription","commits_url":"https://api.github.com/repos/facebook/react-native/commits{/sha}","git_commits_url":"https://api.github.com/repos/facebook/react-native/git/commits{/sha}","comments_url":"https://api.github.com/repos/facebook/react-native/comments{/number}","issue_comment_url":"https://api.github.com/repos/facebook/react-native/issues/comments{/number}","contents_url":"https://api.github.com/repos/facebook/react-native/contents/{+path}","compare_url":"https://api.github.com/repos/facebook/react-native/compare/{base}...{head}","merges_url":"https://api.github.com/repos/facebook/react-native/merges","archive_url":"https://api.github.com/repos/facebook/react-native/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/facebook/react-native/downloads","issues_url":"https://api.github.com/repos/facebook/react-native/issues{/number}","pulls_url":"https://api.github.com/repos/facebook/react-native/pulls{/number}","milestones_url":"https://api.github.com/repos/facebook/react-native/milestones{/number}","notifications_url":"https://api.github.com/repos/facebook/react-native/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/facebook/react-native/labels{/name}","releases_url":"https://api.github.com/repos/facebook/react-native/releases{/id}","deployments_url":"https://api.github.com/repos/facebook/react-native/deployments","created_at":"2015-01-09T18:10:16Z","updated_at":"2017-02-17T23:16:59Z","pushed_at":"2017-02-17T23:47:37Z","git_url":"git://github.com/facebook/react-native.git","ssh_url":"git@github.com:facebook/react-native.git","clone_url":"https://github.com/facebook/react-native.git","svn_url":"https://github.com/facebook/react-native","homepage":"http://facebook.github.io/react-native/","size":113963,"stargazers_count":44218,"watchers_count":44218,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":10190,"mirror_url":null,"open_issues_count":1098,"forks":10190,"open_issues":1098,"watchers":44218,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/facebook/react-native/pulls/12199"},"html":{"href":"https://github.com/facebook/react-native/pull/12199"},"issue":{"href":"https://api.github.com/repos/facebook/react-native/issues/12199"},"comments":{"href":"https://api.github.com/repos/facebook/react-native/issues/12199/comments"},"review_comments":{"href":"https://api.github.com/repos/facebook/react-native/pulls/12199/comments"},"review_comment":{"href":"https://api.github.com/repos/facebook/react-native/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/facebook/react-native/pulls/12199/commits"},"statuses":{"href":"https://api.github.com/repos/facebook/react-native/statuses/b089982ebe9cec0e86a71bf4986c783ac5355e37"}}}}
{"actor":{"display_login":"jpshelley"}}