-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add swipeableTabBar for antd-mobile
- Loading branch information
1 parent
3298991
commit 235bd50
Showing
12 changed files
with
372 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
placeholder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* eslint react/no-multi-comp:0, no-console:0 */ | ||
|
||
import 'rc-tabs/assets/index.less'; | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import Tabs, { TabPane } from 'rc-tabs'; | ||
import TabContent from '../src/SwipeableTabContent'; | ||
import SwipeableInkTabBar from '../src/SwipeableInkTabBar'; | ||
|
||
class PanelContent extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
console.log(this.props.id, 'constructor'); | ||
} | ||
|
||
componentWillReceiveProps() { | ||
console.log(this.props.id, 'componentWillReceiveProps'); | ||
} | ||
|
||
render() { | ||
const count = [1, 1, 1, 1];// new Array(4) skip forEach .... | ||
const els = count.map((c, i) => { | ||
return <p key={i}>{this.props.id}</p>; | ||
}); | ||
return <div>{els}</div>; | ||
} | ||
} | ||
PanelContent.propTypes = { | ||
id: React.PropTypes.number, | ||
}; | ||
|
||
const Component = React.createClass({ | ||
getInitialState() { | ||
return { | ||
activeKey: '', | ||
start: 0, | ||
}; | ||
}, | ||
|
||
onChange(activeKey) { | ||
console.log(`onChange ${activeKey}`); | ||
this.setState({ | ||
activeKey, | ||
}); | ||
}, | ||
|
||
onTabClick(key) { | ||
console.log(`onTabClick ${key}`); | ||
if (key === this.state.activeKey) { | ||
this.setState({ | ||
activeKey: '', | ||
}); | ||
} | ||
}, | ||
|
||
|
||
render() { | ||
const start = this.state.start; | ||
return ( | ||
<div style={{ margin: '20 0', width: '100%' }}> | ||
<span style={{ color: 'red' }}> | ||
Swipe Tabs, please visit this demo at mobile, or chrome simulator | ||
</span> | ||
<Tabs | ||
renderTabBar={() => | ||
<SwipeableInkTabBar | ||
onTabClick={this.onTabClick} | ||
pageSize={4} | ||
speed={8} | ||
/> | ||
} | ||
renderTabContent={() => <TabContent animatedWithMargin />} | ||
activeKey={this.state.activeKey} | ||
onChange={this.onChange} | ||
> | ||
<TabPane tab={`tab ${start}`} key="0"> | ||
<PanelContent id={start}/> | ||
</TabPane> | ||
<TabPane tab={`tab ${start + 1}`} key="1"> | ||
<PanelContent id={start + 1}/> | ||
</TabPane> | ||
<TabPane tab={`tab ${start + 2}`} key="2"> | ||
<PanelContent id={start + 2}/> | ||
</TabPane> | ||
<TabPane tab={`tab ${start + 3}`} key="3"> | ||
<PanelContent id={start + 3}/> | ||
</TabPane> | ||
<TabPane tab={`tab ${start + 4}`} key="4"> | ||
<PanelContent id={start + 4}/> | ||
</TabPane> | ||
<TabPane tab={`tab ${start + 5}`} key="5"> | ||
<PanelContent id={start + 5}/> | ||
</TabPane> | ||
<TabPane tab={`tab ${start + 6}`} key="6"> | ||
<PanelContent id={start + 6}/> | ||
</TabPane> | ||
<TabPane tab={`tab ${start + 7}`} key="7"> | ||
<PanelContent id={start + 7}/> | ||
</TabPane> | ||
</Tabs> | ||
</div> | ||
); | ||
}, | ||
}); | ||
|
||
ReactDOM.render(<Component />, document.getElementById('__react-content')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react'; | ||
import InkTabBarMixin from './InkTabBarMixin'; | ||
import SwipeableTabBarMixin from './SwipeableTabBarMixin'; | ||
import TabBarMixin from './TabBarMixin'; | ||
|
||
const SwipeableInkTabBar = React.createClass({ | ||
mixins: [TabBarMixin, InkTabBarMixin, SwipeableTabBarMixin], | ||
|
||
render() { | ||
const inkBarNode = this.getInkBarNode(); | ||
const tabs = this.getTabs(); | ||
const scrollbarNode = this.getSwipeBarNode([inkBarNode, tabs]); | ||
return this.getRootNode(scrollbarNode); | ||
}, | ||
}); | ||
|
||
export default SwipeableInkTabBar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react'; | ||
import SwipeableTabBarMixin from './SwipeableTabBarMixin'; | ||
import TabBarMixin from './TabBarMixin'; | ||
|
||
|
||
const SwipeableTabBar = React.createClass({ | ||
mixins: [TabBarMixin, SwipeableTabBarMixin], | ||
render() { | ||
const tabs = this.getTabs(); | ||
const swipebarNode = this.getSwipeBarNode(tabs); | ||
return this.getRootNode(swipebarNode); | ||
}, | ||
}); | ||
|
||
export default SwipeableTabBar; |
Oops, something went wrong.