Skip to content

Commit

Permalink
feat: support scrollToTop (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
huhuanming authored Dec 10, 2024
1 parent 3e158b0 commit 8b1a7f5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ios/PagingView/PagingView.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ typedef NSString* _Nonnull (^RenderItemBlock)(NSDictionary *body);

- (void)setVerticalScrollEnabled:(BOOL)verticalScrollEnabled;

- (void)scrollToTop;

@end

NS_ASSUME_NONNULL_END
5 changes: 5 additions & 0 deletions ios/PagingView/PagingView.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ - (void)stopObservingViewPosition {
self.displayLink = nil;
}


- (void)checkViewPosition {
if (_pagingView) {
BOOL isPhone = [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone;
Expand Down Expand Up @@ -228,6 +229,10 @@ - (void) setVerticalScrollEnabled: (BOOL) verticalScrollEnabled {
}
}

- (void)scrollToTop {
[self.pagingView.mainTableView setContentOffset:CGPointMake(0, 0) animated:YES];
}

-(JXPagerView *)pagingView {
if (!_pagingView) {
_pagingView = [[JXPagerView alloc] initWithDelegate:self];
Expand Down
9 changes: 9 additions & 0 deletions ios/PagingView/PagingViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ @implementation PagingViewManager
}];
}

RCT_EXPORT_METHOD(scrollToTop:(nonnull NSNumber *)reactTag) {
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
PagingView *view = (PagingView *)viewRegistry[reactTag];
if (!!view && [view isKindOfClass:[PagingView class]]) {
[view scrollToTop];
}
}];
}

- (UIView *)view
{
return [[PagingView alloc] init];
Expand Down
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.17",
"version": "1.0.18",
"description": "React Native Tab Page View",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
11 changes: 11 additions & 0 deletions src/NestedTabView/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { forwardRef, useImperativeHandle, useRef } from 'react';
import {
UIManager,
findNodeHandle,
Platform,
requireNativeComponent,
} from 'react-native';

Expand All @@ -25,6 +26,16 @@ function NestedTabViewContainer(props: any, forwardRef: any) {
);
}
},
scrollToTop: () => {
if (Platform.OS === 'ios' && ref?.current?._nativeTag) {
UIManager.dispatchViewManagerCommand(
findNodeHandle(ref.current._nativeTag),
UIManager.getViewManagerConfig('NestedTabView').Commands
.scrollToTop as number,
[]
);
}
}
}),
[]
);
Expand Down

0 comments on commit 8b1a7f5

Please sign in to comment.