{"action":"created","comment":{"url":"https://api.github.com/repos/JoelRoxell/r-swipeable/pulls/comments/78827219","id":78827219,"diff_hunk":"@@ -31,16 +30,50 @@ class Swipeable extends Component {\n     this.updateViewMetrics();\n     requestAnimationFrame(this.animateDrag);\n \n-    const contentCenterChildIndex = Math.floor(this.childXCenterPosList.length / 2);\n+    let contentCenterChildIndex = Math.floor(this.childXCenterPosList.length / 2);\n+\n+    if (!isNaN(this.props.currentIndex)) {\n+      contentCenterChildIndex = this.props.currentIndex;\n+    }\n+\n+    const contentPos = this.viewportCenter - this.childXCenterPosList[contentCenterChildIndex].clientXCenter;\n \n     this.setState({\n-      contentPos: this.viewportCenter - this.childXCenterPosList[contentCenterChildIndex].clientXCenter,\n+      contentPos,\n       currentCenteredChildIndex: contentCenterChildIndex\n     });\n   }\n \n-  componentDidUpdate() {\n+  componentWillReceiveProps(nProps) {\n+    // Index state was changed in a component higher up.\n+    if (this.props.currentIndex !== nProps.currentIndex) {\n+      this.positionViewByChildIndex(nProps.currentIndex);\n+    }\n+  }\n+\n+  componentDidUpdate(prevProps, prevState) {\n     this.updateViewMetrics();\n+\n+    const currentIndex = this.props.currentIndex,\n+      childLimitLength = this.childXCenterPosList.length - 1;\n+\n+    if (currentIndex < 0) {\n+      this.props.onChange(0);\n+    } else if (currentIndex > childLimitLength) {\n+      this.props.onChange(childLimitLength);\n+    }\n+\n+    if (prevState.currentCenteredChildIndex === this.state.currentCenteredChildIndex) {\n+      return;\n+    }\n+\n+    if (typeof this.props.onChange === 'function') {\n+      this.props.onChange(this.state.currentCenteredChildIndex);\n+    }\n+  }\n+\n+  shouldComponentUpdate(nProp, nState) {","path":"src/swipeable.js","position":54,"original_position":54,"commit_id":"01ddaea3dd8fe8173cd569b6c8f8da193e3ec71f","original_commit_id":"01ddaea3dd8fe8173cd569b6c8f8da193e3ec71f","user":{"login":"JoelRoxell","id":15216051,"avatar_url":"https://avatars.githubusercontent.com/u/15216051?v=3","gravatar_id":"","url":"https://api.github.com/users/JoelRoxell","html_url":"https://github.com/JoelRoxell","followers_url":"https://api.github.com/users/JoelRoxell/followers","following_url":"https://api.github.com/users/JoelRoxell/following{/other_user}","gists_url":"https://api.github.com/users/JoelRoxell/gists{/gist_id}","starred_url":"https://api.github.com/users/JoelRoxell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JoelRoxell/subscriptions","organizations_url":"https://api.github.com/users/JoelRoxell/orgs","repos_url":"https://api.github.com/users/JoelRoxell/repos","events_url":"https://api.github.com/users/JoelRoxell/events{/privacy}","received_events_url":"https://api.github.com/users/JoelRoxell/received_events","type":"User","site_admin":false},"body":"Remove unnecessary code.","created_at":"2016-09-14T20:00:39Z","updated_at":"2016-09-14T20:09:05Z","html_url":"https://github.com/JoelRoxell/r-swipeable/pull/9#discussion_r78827219","pull_request_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/pulls/9","_links":{"self":{"href":"https://api.github.com/repos/JoelRoxell/r-swipeable/pulls/comments/78827219"},"html":{"href":"https://github.com/JoelRoxell/r-swipeable/pull/9#discussion_r78827219"},"pull_request":{"href":"https://api.github.com/repos/JoelRoxell/r-swipeable/pulls/9"}}},"pull_request":{"url":"https://api.github.com/repos/JoelRoxell/r-swipeable/pulls/9","id":85125527,"html_url":"https://github.com/JoelRoxell/r-swipeable/pull/9","diff_url":"https://github.com/JoelRoxell/r-swipeable/pull/9.diff","patch_url":"https://github.com/JoelRoxell/r-swipeable/pull/9.patch","issue_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/issues/9","number":9,"state":"open","locked":false,"title":"Implemented index hooks by utilizing the onChange callback.","user":{"login":"JoelRoxell","id":15216051,"avatar_url":"https://avatars.githubusercontent.com/u/15216051?v=3","gravatar_id":"","url":"https://api.github.com/users/JoelRoxell","html_url":"https://github.com/JoelRoxell","followers_url":"https://api.github.com/users/JoelRoxell/followers","following_url":"https://api.github.com/users/JoelRoxell/following{/other_user}","gists_url":"https://api.github.com/users/JoelRoxell/gists{/gist_id}","starred_url":"https://api.github.com/users/JoelRoxell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JoelRoxell/subscriptions","organizations_url":"https://api.github.com/users/JoelRoxell/orgs","repos_url":"https://api.github.com/users/JoelRoxell/repos","events_url":"https://api.github.com/users/JoelRoxell/events{/privacy}","received_events_url":"https://api.github.com/users/JoelRoxell/received_events","type":"User","site_admin":false},"body":"`onChange` is triggered on internal swipe actions and passes the new index as the single parameter.\r\n\r\n```js\r\nfunction cb(index) {\r\n  ...\r\n}\r\n\r\n<Swipeable onChange={ cb }>\r\n  ...\r\n</Swipeable>\r\n```\r\n\r\nIt's now also possible to control the index position externally through prop `currentIndex`. If this property is used I advise to use the `onChange` callback to ensure that the containers state index is updated as a internal swipe occurs.\r\n\r\n```js\r\n<Swipeable\r\n  onChange={ this.onChange }\r\n  currentIndex={ this.state.currentIndex }\r\n>\r\n  ...\r\n</Swipeable>\r\n```","created_at":"2016-09-13T21:07:10Z","updated_at":"2016-09-14T20:09:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c005b3e6eda1bc8501e137b0ee3991cf9e6c18b3","assignee":{"login":"JoelRoxell","id":15216051,"avatar_url":"https://avatars.githubusercontent.com/u/15216051?v=3","gravatar_id":"","url":"https://api.github.com/users/JoelRoxell","html_url":"https://github.com/JoelRoxell","followers_url":"https://api.github.com/users/JoelRoxell/followers","following_url":"https://api.github.com/users/JoelRoxell/following{/other_user}","gists_url":"https://api.github.com/users/JoelRoxell/gists{/gist_id}","starred_url":"https://api.github.com/users/JoelRoxell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JoelRoxell/subscriptions","organizations_url":"https://api.github.com/users/JoelRoxell/orgs","repos_url":"https://api.github.com/users/JoelRoxell/repos","events_url":"https://api.github.com/users/JoelRoxell/events{/privacy}","received_events_url":"https://api.github.com/users/JoelRoxell/received_events","type":"User","site_admin":false},"assignees":[{"login":"JoelRoxell","id":15216051,"avatar_url":"https://avatars.githubusercontent.com/u/15216051?v=3","gravatar_id":"","url":"https://api.github.com/users/JoelRoxell","html_url":"https://github.com/JoelRoxell","followers_url":"https://api.github.com/users/JoelRoxell/followers","following_url":"https://api.github.com/users/JoelRoxell/following{/other_user}","gists_url":"https://api.github.com/users/JoelRoxell/gists{/gist_id}","starred_url":"https://api.github.com/users/JoelRoxell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JoelRoxell/subscriptions","organizations_url":"https://api.github.com/users/JoelRoxell/orgs","repos_url":"https://api.github.com/users/JoelRoxell/repos","events_url":"https://api.github.com/users/JoelRoxell/events{/privacy}","received_events_url":"https://api.github.com/users/JoelRoxell/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/pulls/9/commits","review_comments_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/pulls/9/comments","review_comment_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/pulls/comments{/number}","comments_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/issues/9/comments","statuses_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/statuses/01ddaea3dd8fe8173cd569b6c8f8da193e3ec71f","head":{"label":"JoelRoxell:development","ref":"development","sha":"01ddaea3dd8fe8173cd569b6c8f8da193e3ec71f","user":{"login":"JoelRoxell","id":15216051,"avatar_url":"https://avatars.githubusercontent.com/u/15216051?v=3","gravatar_id":"","url":"https://api.github.com/users/JoelRoxell","html_url":"https://github.com/JoelRoxell","followers_url":"https://api.github.com/users/JoelRoxell/followers","following_url":"https://api.github.com/users/JoelRoxell/following{/other_user}","gists_url":"https://api.github.com/users/JoelRoxell/gists{/gist_id}","starred_url":"https://api.github.com/users/JoelRoxell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JoelRoxell/subscriptions","organizations_url":"https://api.github.com/users/JoelRoxell/orgs","repos_url":"https://api.github.com/users/JoelRoxell/repos","events_url":"https://api.github.com/users/JoelRoxell/events{/privacy}","received_events_url":"https://api.github.com/users/JoelRoxell/received_events","type":"User","site_admin":false},"repo":{"id":67898589,"name":"r-swipeable","full_name":"JoelRoxell/r-swipeable","owner":{"login":"JoelRoxell","id":15216051,"avatar_url":"https://avatars.githubusercontent.com/u/15216051?v=3","gravatar_id":"","url":"https://api.github.com/users/JoelRoxell","html_url":"https://github.com/JoelRoxell","followers_url":"https://api.github.com/users/JoelRoxell/followers","following_url":"https://api.github.com/users/JoelRoxell/following{/other_user}","gists_url":"https://api.github.com/users/JoelRoxell/gists{/gist_id}","starred_url":"https://api.github.com/users/JoelRoxell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JoelRoxell/subscriptions","organizations_url":"https://api.github.com/users/JoelRoxell/orgs","repos_url":"https://api.github.com/users/JoelRoxell/repos","events_url":"https://api.github.com/users/JoelRoxell/events{/privacy}","received_events_url":"https://api.github.com/users/JoelRoxell/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/JoelRoxell/r-swipeable","description":"Swipeable react wrapper. (web)","fork":false,"url":"https://api.github.com/repos/JoelRoxell/r-swipeable","forks_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/forks","keys_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/keys{/key_id}","collaborators_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/teams","hooks_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/hooks","issue_events_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/issues/events{/number}","events_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/events","assignees_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/assignees{/user}","branches_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/branches{/branch}","tags_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/tags","blobs_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/git/refs{/sha}","trees_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/git/trees{/sha}","statuses_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/statuses/{sha}","languages_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/languages","stargazers_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/stargazers","contributors_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/contributors","subscribers_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/subscribers","subscription_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/subscription","commits_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/commits{/sha}","git_commits_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/git/commits{/sha}","comments_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/comments{/number}","issue_comment_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/issues/comments{/number}","contents_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/contents/{+path}","compare_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/compare/{base}...{head}","merges_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/merges","archive_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/downloads","issues_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/issues{/number}","pulls_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/pulls{/number}","milestones_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/milestones{/number}","notifications_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/labels{/name}","releases_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/releases{/id}","deployments_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/deployments","created_at":"2016-09-10T22:57:04Z","updated_at":"2016-09-13T21:44:34Z","pushed_at":"2016-09-13T21:07:10Z","git_url":"git://github.com/JoelRoxell/r-swipeable.git","ssh_url":"git@github.com:JoelRoxell/r-swipeable.git","clone_url":"https://github.com/JoelRoxell/r-swipeable.git","svn_url":"https://github.com/JoelRoxell/r-swipeable","homepage":"","size":21,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":9,"forks":0,"open_issues":9,"watchers":0,"default_branch":"master"}},"base":{"label":"JoelRoxell:master","ref":"master","sha":"6d0fbdb1ce68e1591f2decf8d94f04ec92c5f31b","user":{"login":"JoelRoxell","id":15216051,"avatar_url":"https://avatars.githubusercontent.com/u/15216051?v=3","gravatar_id":"","url":"https://api.github.com/users/JoelRoxell","html_url":"https://github.com/JoelRoxell","followers_url":"https://api.github.com/users/JoelRoxell/followers","following_url":"https://api.github.com/users/JoelRoxell/following{/other_user}","gists_url":"https://api.github.com/users/JoelRoxell/gists{/gist_id}","starred_url":"https://api.github.com/users/JoelRoxell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JoelRoxell/subscriptions","organizations_url":"https://api.github.com/users/JoelRoxell/orgs","repos_url":"https://api.github.com/users/JoelRoxell/repos","events_url":"https://api.github.com/users/JoelRoxell/events{/privacy}","received_events_url":"https://api.github.com/users/JoelRoxell/received_events","type":"User","site_admin":false},"repo":{"id":67898589,"name":"r-swipeable","full_name":"JoelRoxell/r-swipeable","owner":{"login":"JoelRoxell","id":15216051,"avatar_url":"https://avatars.githubusercontent.com/u/15216051?v=3","gravatar_id":"","url":"https://api.github.com/users/JoelRoxell","html_url":"https://github.com/JoelRoxell","followers_url":"https://api.github.com/users/JoelRoxell/followers","following_url":"https://api.github.com/users/JoelRoxell/following{/other_user}","gists_url":"https://api.github.com/users/JoelRoxell/gists{/gist_id}","starred_url":"https://api.github.com/users/JoelRoxell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JoelRoxell/subscriptions","organizations_url":"https://api.github.com/users/JoelRoxell/orgs","repos_url":"https://api.github.com/users/JoelRoxell/repos","events_url":"https://api.github.com/users/JoelRoxell/events{/privacy}","received_events_url":"https://api.github.com/users/JoelRoxell/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/JoelRoxell/r-swipeable","description":"Swipeable react wrapper. (web)","fork":false,"url":"https://api.github.com/repos/JoelRoxell/r-swipeable","forks_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/forks","keys_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/keys{/key_id}","collaborators_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/teams","hooks_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/hooks","issue_events_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/issues/events{/number}","events_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/events","assignees_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/assignees{/user}","branches_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/branches{/branch}","tags_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/tags","blobs_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/git/refs{/sha}","trees_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/git/trees{/sha}","statuses_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/statuses/{sha}","languages_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/languages","stargazers_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/stargazers","contributors_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/contributors","subscribers_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/subscribers","subscription_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/subscription","commits_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/commits{/sha}","git_commits_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/git/commits{/sha}","comments_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/comments{/number}","issue_comment_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/issues/comments{/number}","contents_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/contents/{+path}","compare_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/compare/{base}...{head}","merges_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/merges","archive_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/downloads","issues_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/issues{/number}","pulls_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/pulls{/number}","milestones_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/milestones{/number}","notifications_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/labels{/name}","releases_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/releases{/id}","deployments_url":"https://api.github.com/repos/JoelRoxell/r-swipeable/deployments","created_at":"2016-09-10T22:57:04Z","updated_at":"2016-09-13T21:44:34Z","pushed_at":"2016-09-13T21:07:10Z","git_url":"git://github.com/JoelRoxell/r-swipeable.git","ssh_url":"git@github.com:JoelRoxell/r-swipeable.git","clone_url":"https://github.com/JoelRoxell/r-swipeable.git","svn_url":"https://github.com/JoelRoxell/r-swipeable","homepage":"","size":21,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":9,"forks":0,"open_issues":9,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/JoelRoxell/r-swipeable/pulls/9"},"html":{"href":"https://github.com/JoelRoxell/r-swipeable/pull/9"},"issue":{"href":"https://api.github.com/repos/JoelRoxell/r-swipeable/issues/9"},"comments":{"href":"https://api.github.com/repos/JoelRoxell/r-swipeable/issues/9/comments"},"review_comments":{"href":"https://api.github.com/repos/JoelRoxell/r-swipeable/pulls/9/comments"},"review_comment":{"href":"https://api.github.com/repos/JoelRoxell/r-swipeable/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/JoelRoxell/r-swipeable/pulls/9/commits"},"statuses":{"href":"https://api.github.com/repos/JoelRoxell/r-swipeable/statuses/01ddaea3dd8fe8173cd569b6c8f8da193e3ec71f"}}}}
{"actor":{"display_login":"JoelRoxell"}}