Skip to content

Commit

Permalink
fix: Native driven events only support animated values contained insi…
Browse files Browse the repository at this point in the history
…de 'nativeEvent'

feat: Added props errorToThrow
  • Loading branch information
itenl committed Sep 11, 2021
1 parent 5a8caf3 commit 343b9e8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README-zh_CN.md
Expand Up @@ -181,6 +181,8 @@ Prop | Type | Default | Description
**`onScroll2Horizontal`** | Function | null | 滚动事件监听(横向)
**`tabsEnableAnimated`** | Boolean | false | 为Tabs启用滑动效果,需要为 **`tabStyle`** 指定 **`width`**
**`tabsEnableAnimatedUnderlineWidth`** | Number | 0 | 为Tabs Underline设定固定宽度并添加弹跳动画,需要启用 **`tabsEnableAnimated=true`**.( 建议传入 **`tabStyle.width`** 的三分之一或固定 30px )
**`errorToThrow`** | Boolean | false | **`console.error`** 将会抛出错误 **`throw new Error()`**


## <a name="method"/>Method

Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -181,6 +181,7 @@ Prop | Type | Default | Description
**`onScroll2Horizontal`** | Function | null | Scroll event monitoring for orizontal
**`tabsEnableAnimated`** | Boolean | false | Enable sliding effect for Tabs, Need to specify **`width`** for **`tabStyle`**
**`tabsEnableAnimatedUnderlineWidth`** | Number | 0 | To set a fixed width for the Tabs Underline and add a jumping animation, you need to enable **`tabsEnableAnimated=true`**. (It is recommended to pass in one third of **`tabStyle.width`** or a fixed 30px)
**`errorToThrow`** | Boolean | false | **`console.error`** will throw an error **`throw new Error()`**

## <a name="method"/>Method

Expand Down
24 changes: 15 additions & 9 deletions src/index.js
Expand Up @@ -60,7 +60,8 @@ export default class ScrollableTabView extends React.Component {
titleArgs: PropTypes.object,
onScroll: PropTypes.func,
onScroll2Horizontal: PropTypes.func,
screenScrollThrottle: PropTypes.number
screenScrollThrottle: PropTypes.number,
errorToThrow: PropTypes.bool
};

static defaultProps = {
Expand Down Expand Up @@ -104,7 +105,8 @@ export default class ScrollableTabView extends React.Component {
},
onScroll: null,
onScroll2Horizontal: null,
screenScrollThrottle: 60
screenScrollThrottle: 60,
errorToThrow: false
};

constructor(props) {
Expand Down Expand Up @@ -382,11 +384,10 @@ export default class ScrollableTabView extends React.Component {
}

_getTabUnderlineInterpolateArgs(tabsEnableAnimatedUnderlineWidth) {
const tabsCount = this.tabs.length - 1;
if (tabsCount * 2 + 1 === this.tabUnderlineInterpolateArgs.inputRange.length) return this.tabUnderlineInterpolateArgs;
const maxTranslateXVal = deviceWidth * tabsCount;
const maxTranslateXCount = this.tabs.length * 2 - 1;
if (maxTranslateXCount === this.tabUnderlineInterpolateArgs.inputRange.length) return this.tabUnderlineInterpolateArgs;
const _outputRange = [];
const _inputRange = Array.from({ length: maxTranslateXVal / (deviceWidth / 2) + 1 }, (v, k) => {
const _inputRange = Array.from({ length: maxTranslateXCount }, (v, k) => {
_outputRange.push(k % 2 ? this.tabWidth / tabsEnableAnimatedUnderlineWidth : 1);
return k == 0 ? k : (k * deviceWidth) / 2;
});
Expand Down Expand Up @@ -433,8 +434,11 @@ export default class ScrollableTabView extends React.Component {
}

_displayConsole(message, level = CONSOLE_LEVEL.WARN) {
const { errorToThrow } = this.props;
const pluginName = packagejson.name;
console[level](`${pluginName}: ${message || ' --- '}`);
const msg = `${pluginName}: ${message || ' --- '}`;
console[level](msg);
if (errorToThrow) throw new Error(msg);
}

_errorProps(propName, level) {
Expand Down Expand Up @@ -586,8 +590,10 @@ export default class ScrollableTabView extends React.Component {
!ref && this._displayConsole(`The Screen Ref is lost when calling onEndReached. Please confirm whether the Stack is working properly.(index: ${this.state.checkedIndex})`);
if (ref && ref.onEndReached && typeof ref.onEndReached === 'function') ref.onEndReached();
};
const { onBeforeEndReached } = this.props;
onBeforeEndReached && typeof onBeforeEndReached === 'function' ? onBeforeEndReached(next) : next();
if (this.state.checkedIndex != null) {
const { onBeforeEndReached } = this.props;
onBeforeEndReached && typeof onBeforeEndReached === 'function' ? onBeforeEndReached(next) : next();
}
}

_toggledRefreshing(status) {
Expand Down

0 comments on commit 343b9e8

Please sign in to comment.