diff --git a/android/src/main/java/so/onekey/app/wallet/viewManager/homePage/HomePageManager.kt b/android/src/main/java/so/onekey/app/wallet/viewManager/homePage/HomePageManager.kt index bb06ddb..1e803fd 100644 --- a/android/src/main/java/so/onekey/app/wallet/viewManager/homePage/HomePageManager.kt +++ b/android/src/main/java/so/onekey/app/wallet/viewManager/homePage/HomePageManager.kt @@ -24,8 +24,9 @@ data class TabProps( class HomePageManager : ViewGroupManager() { companion object { - const val COMMAND_SET_PAGE_INDEX = "setPageIndex" - const val COMMAND_SET_REFRESHING = "setRefreshing" + const val COMMAND_SET_PAGE_INDEX = 1 + const val COMMAND_SET_REFRESHING = 2 + const val COMMAND_SET_VERTICAL_SCROLL_ENABLED = 3 } private val REACT_CLASS = "NestedTabView" @@ -137,8 +138,15 @@ class HomePageManager : ViewGroupManager() { ) } + override fun getCommandsMap(): Map { + return mapOf( + "setPageIndex" to COMMAND_SET_PAGE_INDEX, + "setRefreshing" to COMMAND_SET_REFRESHING, + "setVerticalScrollEnabled" to COMMAND_SET_VERTICAL_SCROLL_ENABLED + ) + } - override fun receiveCommand(view: HomePageView, commandId: String?, args: ReadableArray?) { + override fun receiveCommand(view: HomePageView, commandId: Int, args: ReadableArray?) { super.receiveCommand(view, commandId, args) when (commandId) { COMMAND_SET_PAGE_INDEX -> if (args != null) { @@ -150,6 +158,11 @@ class HomePageManager : ViewGroupManager() { val refresh = args.getBoolean(0) view.setRefresh(refresh) } + + COMMAND_SET_VERTICAL_SCROLL_ENABLED -> if (args != null) { + val enabled = args.getBoolean(0) + view.setVerticalScrollEnabled(enabled) + } } } diff --git a/android/src/main/java/so/onekey/app/wallet/widget/HomePageLayout.kt b/android/src/main/java/so/onekey/app/wallet/widget/HomePageLayout.kt index 3ecfa81..26f6506 100644 --- a/android/src/main/java/so/onekey/app/wallet/widget/HomePageLayout.kt +++ b/android/src/main/java/so/onekey/app/wallet/widget/HomePageLayout.kt @@ -56,6 +56,8 @@ open class HomePageLayout @JvmOverloads constructor( private var mAppBarExtended = true private var mHeaderHeight = 56 + private var mVerticalScrollEnabled = true + val eventDispatcher = (context as ReactContext).getNativeModule(UIManagerModule::class.java)?.eventDispatcher @@ -138,6 +140,21 @@ open class HomePageLayout @JvmOverloads constructor( } } + fun setVerticalScrollEnabled(enabled: Boolean) { + mVerticalScrollEnabled = enabled + content.findViewById(R.id.appbar)?.let { + it.setExpanded(true, false) + val params = it.layoutParams as androidx.coordinatorlayout.widget.CoordinatorLayout.LayoutParams + val behavior = AppBarLayout.Behavior() + behavior.setDragCallback(object : AppBarLayout.Behavior.DragCallback() { + override fun canDrag(appBarLayout: AppBarLayout): Boolean { + return mVerticalScrollEnabled + } + }) + params.behavior = behavior + } + } + fun initRefreshListener() { content.findViewById(R.id.layout_refresh)?.let { it.setOnRefreshListener { diff --git a/ios/PagingView/PagingView.h b/ios/PagingView/PagingView.h index 9800e90..6de3ca7 100644 --- a/ios/PagingView/PagingView.h +++ b/ios/PagingView/PagingView.h @@ -18,6 +18,8 @@ typedef NSString* _Nonnull (^RenderItemBlock)(NSDictionary *body); - (void)setRefresh:(BOOL)refresh; +- (void)setVerticalScrollEnabled:(BOOL)verticalScrollEnabled; + @end NS_ASSUME_NONNULL_END diff --git a/ios/PagingView/PagingView.m b/ios/PagingView/PagingView.m index 88090f1..df68bd3 100644 --- a/ios/PagingView/PagingView.m +++ b/ios/PagingView/PagingView.m @@ -37,6 +37,7 @@ @interface PagingView () @property (nonatomic, assign) BOOL refresh; @property (nonatomic, assign) BOOL disableRefresh; +@property (nonatomic, assign) BOOL verticalScrollEnabled; @property (nonatomic, copy) NSString *spinnerColor; @property (nonatomic, weak) UIWindow *window; @@ -52,6 +53,7 @@ -(instancetype)init { if (self){ NSLog(@"PagingView init"); [self startObservingViewPosition]; + _verticalScrollEnabled = YES; _isScrolling = NO; } return self; @@ -92,7 +94,6 @@ - (void)checkViewPosition { } } - - (void)setPageIndex:(NSInteger)index{ [self.tabView.categoryView selectItemAtIndex:index]; } @@ -220,6 +221,13 @@ -(void)setDisableRefresh:(BOOL)disableRefresh { } +- (void) setVerticalScrollEnabled: (BOOL) verticalScrollEnabled { + if (_verticalScrollEnabled != verticalScrollEnabled) { + _verticalScrollEnabled = verticalScrollEnabled; + self.pagingView.mainTableView.scrollEnabled = verticalScrollEnabled; + } +} + -(JXPagerView *)pagingView { if (!_pagingView) { _pagingView = [[JXPagerView alloc] initWithDelegate:self]; @@ -238,6 +246,10 @@ -(JXPagerView *)pagingView { [_pagingView.listContainerView.scrollView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil]; [self addSubview:_pagingView]; } + + if (_pagingView != nil && _pagingView.mainTableView.scrollEnabled != self.verticalScrollEnabled) { + _pagingView.mainTableView.scrollEnabled = self.verticalScrollEnabled; + } return _pagingView; } diff --git a/ios/PagingView/PagingViewManager.m b/ios/PagingView/PagingViewManager.m index 52ee16e..5df804a 100644 --- a/ios/PagingView/PagingViewManager.m +++ b/ios/PagingView/PagingViewManager.m @@ -44,6 +44,15 @@ @implementation PagingViewManager }]; } +RCT_EXPORT_METHOD(setVerticalScrollEnabled:(nonnull NSNumber *)reactTag verticalScrollEnabled:(BOOL)verticalScrollEnabled) { + [self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary *viewRegistry) { + PagingView *view = (PagingView *)viewRegistry[reactTag]; + if (!!view && [view isKindOfClass:[PagingView class]]) { + [view setVerticalScrollEnabled:verticalScrollEnabled]; + } + }]; +} + - (UIView *)view { return [[PagingView alloc] init]; diff --git a/package.json b/package.json index 73ac18f..c729956 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@onekeyfe/react-native-tab-page-view", - "version": "1.0.16", + "version": "1.0.17", "description": "React Native Tab Page View", "main": "lib/commonjs/index", "module": "lib/module/index", diff --git a/src/NestedTabView/index.native.tsx b/src/NestedTabView/index.native.tsx index c52be18..45877bd 100644 --- a/src/NestedTabView/index.native.tsx +++ b/src/NestedTabView/index.native.tsx @@ -1,14 +1,38 @@ -import { useRef } from 'react'; +import { forwardRef, useImperativeHandle, useRef } from 'react'; -import { requireNativeComponent } from 'react-native'; +import { + UIManager, + findNodeHandle, + requireNativeComponent, +} from 'react-native'; const BaseNestedTabView = requireNativeComponent('NestedTabView'); -function NestedTabViewContainer(props: any) { +function NestedTabViewContainer(props: any, forwardRef: any) { const point = useRef({ x: 0, y: 0 }); + const ref = useRef<{ _nativeTag?: number }>(); + + useImperativeHandle( + forwardRef, + () => ({ + setVerticalScrollEnabled: (scrollEnabled: boolean) => { + if (ref?.current?._nativeTag) { + UIManager.dispatchViewManagerCommand( + findNodeHandle(ref.current._nativeTag), + UIManager.getViewManagerConfig('NestedTabView').Commands + .setVerticalScrollEnabled as number, + [scrollEnabled] + ); + } + }, + }), + [] + ); + return ( // @ts-ignore { const { locationX: x, locationY: y } = e.nativeEvent; point.current = { x, y }; @@ -25,4 +49,4 @@ function NestedTabViewContainer(props: any) { ); } -export default NestedTabViewContainer; +export default forwardRef(NestedTabViewContainer);