Skip to content

Commit

Permalink
feat(tab-set): tab change event
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur Yorsh committed Oct 23, 2018
1 parent 141254e commit 11f315d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions example/screens/tabset/TabViewScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export class TabViewScreen extends React.Component {
title: 'Tab Set',
};

onItemChange = (change) => {
console.log(`onItemChange: ${JSON.stringify(change, null, 2)}`);
};

render() {
return (
<View style={styles.container}>
Expand Down
14 changes: 12 additions & 2 deletions src/components/tabset/rkTabView.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { RkTabPager } from './rkTabPager.component';
/**
* @extends React.Component
*
* @property {function} onGalleryItemChange - Gallery (modal) item change callback
* @property {function} onItemChange - tab content change callback
*/
export class RkTabView extends React.Component {
static propTypes = {
Expand Down Expand Up @@ -36,15 +36,25 @@ export class RkTabView extends React.Component {
this.state.selectedIndex = this.tabViews.findIndex(child => child.props.isSelected);
}

componentDidMount() {
this.props.onItemChange({
previous: null,
current: this.state.selectedIndex,
});
}

onTabSelect = (index) => {
this.tabPagerRef.scrollToIndex({ index });
};

onTabContentSelect = (index) => {
this.props.onItemChange({
previous: this.state.selectedIndex,
current: index,
});
this.setState({
selectedIndex: index,
});
this.props.onItemChange(index);
};

setTabBarRef = (ref) => {
Expand Down

0 comments on commit 11f315d

Please sign in to comment.