Skip to content

Commit 11f315d

Browse files
author
Artur Yorsh
committed
feat(tab-set): tab change event
1 parent 141254e commit 11f315d

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

example/screens/tabset/TabViewScreen.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export class TabViewScreen extends React.Component {
1212
title: 'Tab Set',
1313
};
1414

15+
onItemChange = (change) => {
16+
console.log(`onItemChange: ${JSON.stringify(change, null, 2)}`);
17+
};
18+
1519
render() {
1620
return (
1721
<View style={styles.container}>

src/components/tabset/rkTabView.component.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { RkTabPager } from './rkTabPager.component';
88
/**
99
* @extends React.Component
1010
*
11-
* @property {function} onGalleryItemChange - Gallery (modal) item change callback
11+
* @property {function} onItemChange - tab content change callback
1212
*/
1313
export class RkTabView extends React.Component {
1414
static propTypes = {
@@ -36,15 +36,25 @@ export class RkTabView extends React.Component {
3636
this.state.selectedIndex = this.tabViews.findIndex(child => child.props.isSelected);
3737
}
3838

39+
componentDidMount() {
40+
this.props.onItemChange({
41+
previous: null,
42+
current: this.state.selectedIndex,
43+
});
44+
}
45+
3946
onTabSelect = (index) => {
4047
this.tabPagerRef.scrollToIndex({ index });
4148
};
4249

4350
onTabContentSelect = (index) => {
51+
this.props.onItemChange({
52+
previous: this.state.selectedIndex,
53+
current: index,
54+
});
4455
this.setState({
4556
selectedIndex: index,
4657
});
47-
this.props.onItemChange(index);
4858
};
4959

5060
setTabBarRef = (ref) => {

0 commit comments

Comments
 (0)