Skip to content

Commit

Permalink
feat: auto scroll to the center
Browse files Browse the repository at this point in the history
  • Loading branch information
hellohublot committed Jun 13, 2024
1 parent 48c5cf2 commit 365a23e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/react-native-tab-page-view",
"version": "1.0.3",
"version": "1.0.4",
"description": "React Native Tab Page View",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
7 changes: 6 additions & 1 deletion src/PageHeaderView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export default class PageHeaderView extends Component<PageHeaderViewProps> {
});
private scrollView: RefObject<ScrollView> = React.createRef();
private cursor: RefObject<PageHeaderCursor> = React.createRef();
private scrollViewWidth = 0;

static defaultProps: PageHeaderViewProps = {
data: [],
Expand Down Expand Up @@ -127,7 +128,7 @@ export default class PageHeaderView extends Component<PageHeaderViewProps> {
const itemLayout = this?.cursor?.current?.state
?.itemContainerLayoutList?.[newPageIndex] ?? { x: 0, width: 0 };
this?.scrollView?.current?.scrollTo({
x: itemLayout.x - itemLayout.width,
x: itemLayout.x + itemLayout.width / 2.0 - this.scrollViewWidth / 2.0,
});
this.scrollPageIndex = newPageIndex;
}
Expand Down Expand Up @@ -275,6 +276,10 @@ export default class PageHeaderView extends Component<PageHeaderViewProps> {
);
this?.props?.onContentSizeChange?.(width, height);
}}
onLayout={(event) => {
this.scrollViewWidth = event.nativeEvent.layout.width;
this?.props?.onLayout?.(event);
}}
style={this.props.containerStyle}
{...restProps}
contentContainerStyle={[
Expand Down

0 comments on commit 365a23e

Please sign in to comment.