Skip to content

Commit 11196b7

Browse files
authored
Merge pull request #27 from itenl/dev-1.1.6
Dev 1.1.6
2 parents 7ddf7e3 + c2c16ba commit 11196b7

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

README-zh_CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ Prop | Type | Default | Description
163163
**`onTabviewChanged`** | Function | null | Tab切换完成回调 (回调含有 **`index`**, **`tabLabel`** 两个形参)
164164
**`screenScrollThrottle`** | Number | 60 | **`Screen`** 横向滑动时节流参数,单位 (毫秒)
165165
**`header`** | Function / JSX Element / Class Component | null | 顶部组件 (若是函数需要返回 Element)
166+
**`stickyHeader`** | Function / JSX Element / Class Component | null | 顶部带吸顶效果组件 (若是函数需要返回 Element)
166167
**`oneTabHidden`** | Boolean | false | 仅一个Tab时将隐藏自身
167168
**`enableCachePage`** | Boolean | true | 是否持久化页面切换后不销毁
168169
**`carouselProps`** | Object | {} | 传递给 Carousel 的剩余属性 < [阅读 Carousel](https://github.com/meliorence/react-native-snap-carousel/blob/master/doc/PROPS_METHODS_AND_GETTERS.md) >

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ Prop | Type | Default | Description
163163
**`onTabviewChanged`** | Function | null | Tab switch completion callback (callback contains **`index`**, **`tabLabel`** two formal parameters)
164164
**`screenScrollThrottle`** | Number | 60 | **`Screen`** Throttle parameters during lateral sliding, Unit (ms)
165165
**`header`** | Function / JSX Element / Class Component | null | Top component (if the function needs to return Element)
166+
**`stickyHeader`** | Function / JSX Element / Class Component | null | Top component (if the function needs to return Element) for sticky
166167
**`oneTabHidden`** | Boolean | false | Hide itself when there is only one Tab
167168
**`enableCachePage`** | Boolean | true | Whether the persistent page will not be destroyed after switching
168169
**`carouselProps`** | Object | {} | The remaining attributes passed to Carousel < [Read Carousel](https://github.com/meliorence/react-native-snap-carousel/blob/master/doc/PROPS_METHODS_AND_GETTERS.md) >

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@itenl/react-native-scrollable-tabview",
3-
"version": "1.1.5",
3+
"version": "1.1.6",
44
"description": "react-native-scrollable-tabview",
55
"main": "index.js",
66
"scripts": {

src/index.js

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default class ScrollableTabView extends React.Component {
2828
firstIndex: PropTypes.number,
2929
mappingProps: PropTypes.object,
3030
header: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
31+
stickyHeader: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
3132
badges: PropTypes.array,
3233
tabsStyle: PropTypes.object,
3334
tabWrapStyle: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
@@ -69,6 +70,7 @@ export default class ScrollableTabView extends React.Component {
6970
firstIndex: null,
7071
mappingProps: {},
7172
header: null,
73+
stickyHeader: null,
7274
badges: [],
7375
tabsStyle: {},
7476
tabWrapStyle: {},
@@ -118,7 +120,7 @@ export default class ScrollableTabView extends React.Component {
118120
this._initial();
119121
}
120122

121-
componentWillReceiveProps(newProps) {
123+
UNSAFE_componentWillReceiveProps(newProps) {
122124
this._initial(newProps, true);
123125
}
124126

@@ -141,6 +143,7 @@ export default class ScrollableTabView extends React.Component {
141143
this.layoutHeight = {
142144
container: 0,
143145
header: 0,
146+
stickyHeader: 0,
144147
tabs: 0,
145148
screen: 0
146149
};
@@ -285,6 +288,7 @@ export default class ScrollableTabView extends React.Component {
285288
_scrollTo = y => {
286289
if (typeof y == 'number') {
287290
this.section &&
291+
this.section.scrollToLocation &&
288292
this.section.scrollToLocation({
289293
itemIndex: 0,
290294
viewOffset: 0 - y
@@ -331,7 +335,7 @@ export default class ScrollableTabView extends React.Component {
331335
_renderSticky() {
332336
const stacks = this.props.stacks[this.state.checkedIndex];
333337
const ref = this.getCurrentRef();
334-
if (stacks && stacks.sticky && typeof stacks.sticky == 'function' && ref) {
338+
if (stacks && stacks.sticky && typeof stacks.sticky == 'function' && ref && stacks.__id__ === ref.__id__) {
335339
// 用于自动同步 Screen 数据流改变后仅会 render 自身 Screen 的问题,用于自动同步 screenContext 给吸顶组件
336340
if (this.props.syncToSticky && !ref.__isOverride__) {
337341
const originalDidUpdate = ref.componentDidUpdate,
@@ -496,6 +500,7 @@ export default class ScrollableTabView extends React.Component {
496500
return (
497501
<View style={{ flex: 1 }}>
498502
{this._renderHeader(fixedHeader)}
503+
{this._renderStickyHeader()}
499504
{this._renderTabs()}
500505
{this._renderSticky()}
501506
</View>
@@ -524,7 +529,7 @@ export default class ScrollableTabView extends React.Component {
524529
if (!this.stacks[index]) return;
525530
const { enableCachePage, toHeaderOnTab, toTabsOnTab, onTabviewChanged } = this.props;
526531
if (index == this.state.checkedIndex) {
527-
if (!isCarouselScroll && toHeaderOnTab) return this._scrollTo(-this.layoutHeight['header']);
532+
if (!isCarouselScroll && toHeaderOnTab) return this._scrollTo(-(this.layoutHeight['header'] + this.layoutHeight['stickyHeader']));
528533
if (!isCarouselScroll && toTabsOnTab) return this._scrollTo(0);
529534
return void 0;
530535
}
@@ -556,12 +561,12 @@ export default class ScrollableTabView extends React.Component {
556561
}
557562

558563
_getScreenHeight() {
559-
this.layoutHeight['screen'] = this.layoutHeight['container'] - (this.layoutHeight['header'] + this.layoutHeight['tabs']);
564+
this.layoutHeight['screen'] = this.layoutHeight['container'] - (this.layoutHeight['header'] + this.layoutHeight['stickyHeader'] + this.layoutHeight['tabs']);
560565
return this.layoutHeight['screen'];
561566
}
562567

563568
_getMaximumScreenHeight() {
564-
return this.layoutHeight['container'] - this.layoutHeight['tabs'];
569+
return this.layoutHeight['container'] - this.layoutHeight['stickyHeader'] - this.layoutHeight['tabs'];
565570
}
566571

567572
_renderItem({ item, index }) {
@@ -632,6 +637,23 @@ export default class ScrollableTabView extends React.Component {
632637
);
633638
};
634639

640+
_renderStickyHeader = () => {
641+
const { stickyHeader } = this.props;
642+
return (
643+
stickyHeader && (
644+
<View
645+
onLayout={({ nativeEvent }) => {
646+
const { height } = nativeEvent.layout;
647+
this.layoutHeight['stickyHeader'] = height;
648+
if (height !== 0) this._refresh();
649+
}}
650+
>
651+
{typeof stickyHeader === 'function' ? stickyHeader() : stickyHeader}
652+
</View>
653+
)
654+
);
655+
};
656+
635657
_renderTitle = () => {
636658
const { title, titleArgs } = this.props;
637659
if (!title) return null;
@@ -720,6 +742,7 @@ export default class ScrollableTabView extends React.Component {
720742
<AnimatedCarousel
721743
ref={c => (this.tabview = c)}
722744
pagingEnabled={true}
745+
inactiveSlideOpacity={1}
723746
inactiveSlideScale={1}
724747
data={this.stacks}
725748
renderItem={this._renderItem}

0 commit comments

Comments
 (0)