Skip to content

Commit 7019c96

Browse files
committed
feat(ios): nested scroll api support (#4149)
* feat(ios): nested scroll api support * feat(ios): nested scroll api support part2 * feat(ios): nested scroll api support part3 * feat(ios): nested scroll api support, add test * docs(js): add nested scroll api's docs
1 parent 72fe2d2 commit 7019c96

17 files changed

+903
-19
lines changed

docs/api/hippy-react/components.md

+36
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,24 @@ import icon from './qb_icon_new.png';
130130
| editable | 是否可编辑,开启侧滑删除时需要设置为 `true``最低支持版本2.9.0` | `boolean` | `iOS` |
131131
| delText | 侧滑删除文本。`最低支持版本2.9.0` | `string` | `iOS` |
132132
| onDelete | 在列表项侧滑删除时调起。`最低支持版本2.9.0` | `(nativeEvent: { index: number}) => void` | `iOS` |
133+
| nestedScrollPriority* | 嵌套滚动事件处理优先级,`default:self`。相当于同时设置 `nestedScrollLeftPriority``nestedScrollTopPriority``nestedScrollRightPriority``nestedScrollBottomPriority``Android最低支持版本 2.16.0,iOS最低支持版本3.3.3` | `enum(self,parent,none)` | `Android、iOS` |
134+
| nestedScrollLeftPriority | 嵌套时**从右往左**滚动事件的处理优先级,会覆盖 `nestedScrollPriority` 对应方向的值。`最低支持版本 2.16.0,iOS最低支持版本3.3.3` | `enum(self,parent,none)` | `Android、iOS` |
135+
| nestedScrollTopPriority | 嵌套时**从下往上**滚动事件的处理优先级,会覆盖 `nestedScrollPriority` 对应方向的值。`最低支持版本 2.16.0,iOS最低支持版本3.3.3` | `enum(self,parent,none)` | `Android、iOS` |
136+
| nestedScrollRightPriority | 嵌套时**从左往右**滚动事件的处理优先级,会覆盖 `nestedScrollPriority` 对应方向的值。`最低支持版本 2.16.0,iOS最低支持版本3.3.3` | `enum(self,parent,none)` | `Android、iOS` |
137+
| nestedScrollBottomPriority | 嵌套时**从上往下**滚动事件的处理优先级,会覆盖 `nestedScrollPriority` 对应方向的值。`最低支持版本 2.16.0,iOS最低支持版本3.3.3` | `enum(self,parent,none)` | `Android、iOS` |
138+
139+
* nestedScrollPriority 的参数含义:
140+
141+
* `self`:当前组件优先,滚动事件将先由当前组件消费,剩余部分传递给父组件消费;
142+
143+
* `parent`:父组件优先,滚动事件将先由父组件消费,剩余部分再由当前组件消费;
144+
145+
* `none`:不允许嵌套滚动,滚动事件将不会传递给父组件。
146+
147+
* nestedScrollPriority 默认值的说明:
148+
149+
如未设置任何滚动优先级时,iOS平台的默认值为`none`,即与系统默认行为保持一致。当指定任意一方向的优先级后,其他方向默认值为`self`
150+
Android平台默认值始终为`self`
133151

134152
## 方法
135153

@@ -253,6 +271,24 @@ import icon from './qb_icon_new.png';
253271
| showScrollIndicator | 是否显示滚动条。 `default: false` | `boolean` | `Android、hippy-react-web、Voltron` |
254272
| showsHorizontalScrollIndicator | 当此值设为 `false` 的时候,`ScrollView` 会隐藏水平的滚动条。`default: true` | `boolean` | `iOS、Voltron` |
255273
| showsVerticalScrollIndicator | 当此值设为 `false` 的时候,`ScrollView` 会隐藏垂直的滚动条。 `default: true` | `boolean` | `iOS、Voltron` |
274+
| nestedScrollPriority* | 嵌套滚动事件处理优先级,`default:self`。相当于同时设置 `nestedScrollLeftPriority``nestedScrollTopPriority``nestedScrollRightPriority``nestedScrollBottomPriority``Android最低支持版本 2.16.0,iOS最低支持版本3.3.3` | `enum(self,parent,none)` | `Android、iOS` |
275+
| nestedScrollLeftPriority | 嵌套时**从右往左**滚动事件的处理优先级,会覆盖 `nestedScrollPriority` 对应方向的值。`最低支持版本 2.16.0,iOS最低支持版本3.3.3` | `enum(self,parent,none)` | `Android、iOS` |
276+
| nestedScrollTopPriority | 嵌套时**从下往上**滚动事件的处理优先级,会覆盖 `nestedScrollPriority` 对应方向的值。`最低支持版本 2.16.0,iOS最低支持版本3.3.3` | `enum(self,parent,none)` | `Android、iOS` |
277+
| nestedScrollRightPriority | 嵌套时**从左往右**滚动事件的处理优先级,会覆盖 `nestedScrollPriority` 对应方向的值。`最低支持版本 2.16.0,iOS最低支持版本3.3.3` | `enum(self,parent,none)` | `Android、iOS` |
278+
| nestedScrollBottomPriority | 嵌套时**从上往下**滚动事件的处理优先级,会覆盖 `nestedScrollPriority` 对应方向的值。`最低支持版本 2.16.0,iOS最低支持版本3.3.3` | `enum(self,parent,none)` | `Android、iOS` |
279+
280+
* nestedScrollPriority 的参数含义:
281+
282+
* `self`(默认值):当前组件优先,滚动事件将先由当前组件消费,剩余部分传递给父组件消费;
283+
284+
* `parent`:父组件优先,滚动事件将先由父组件消费,剩余部分再由当前组件消费;
285+
286+
* `none`:不允许嵌套滚动,滚动事件将不会传递给父组件。
287+
288+
* nestedScrollPriority 默认值的说明:
289+
290+
如未设置任何滚动优先级时,iOS平台的默认值为`none`,即与系统默认行为保持一致。当指定任意一方向的优先级后,其他方向默认值为`self`
291+
Android平台默认值始终为`self`
256292

257293
## 方法
258294

docs/api/hippy-vue/components.md

+36
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,24 @@
6868
| showsVerticalScrollIndicator | 当此值设为 `false` 的时候,`ScrollView` 会隐藏垂直的滚动条。 `default: true` `(仅在 overflow-y/x: scroll 时适用)`| `boolean` | `iOS、Voltron` |
6969
| nativeBackgroundAndroid | 配置水波纹效果,`最低支持版本 2.13.1`;配置项为 `{ borderless: boolean, color: Color, rippleRadius: number }``borderless` 表示波纹是否有边界,默认false;`color` 波纹颜色;`rippleRadius` 波纹半径,若不设置,默认容器边框为边界; `注意:设置水波纹后默认不显示,需要在对应触摸事件中调用 setPressed 和 setHotspot 方法进行水波纹展示,详情参考相关`[demo](//github.com/Tencent/Hippy/tree/master/examples/hippy-vue-demo/src/components/demos/demo-div.vue) | `Object`| `Android` |
7070
| pointerEvents | 用于控制视图是否可以成为触摸事件的目标。 | `enum('box-none', 'none', 'box-only', 'auto')` | `iOS` |
71+
| nestedScrollPriority* | 嵌套滚动事件处理优先级,`default:self`。相当于同时设置 `nestedScrollLeftPriority``nestedScrollTopPriority``nestedScrollRightPriority``nestedScrollBottomPriority``Android最低支持版本 2.16.0,iOS最低支持版本3.3.3` | `enum(self,parent,none)` | `Android、iOS` |
72+
| nestedScrollLeftPriority | 嵌套时**从右往左**滚动事件的处理优先级,会覆盖 `nestedScrollPriority` 对应方向的值。`最低支持版本 2.16.0,iOS最低支持版本3.3.3` | `enum(self,parent,none)` | `Android、iOS` |
73+
| nestedScrollTopPriority | 嵌套时**从下往上**滚动事件的处理优先级,会覆盖 `nestedScrollPriority` 对应方向的值。`最低支持版本 2.16.0,iOS最低支持版本3.3.3` | `enum(self,parent,none)` | `Android、iOS` |
74+
| nestedScrollRightPriority | 嵌套时**从左往右**滚动事件的处理优先级,会覆盖 `nestedScrollPriority` 对应方向的值。`最低支持版本 2.16.0,iOS最低支持版本3.3.3` | `enum(self,parent,none)` | `Android、iOS` |
75+
| nestedScrollBottomPriority | 嵌套时**从上往下**滚动事件的处理优先级,会覆盖 `nestedScrollPriority` 对应方向的值。`最低支持版本 2.16.0,iOS最低支持版本3.3.3` | `enum(self,parent,none)` | `Android、iOS` |
76+
77+
* nestedScrollPriority 的参数含义:
78+
79+
* `self`(默认值):当前组件优先,滚动事件将先由当前组件消费,剩余部分传递给父组件消费;
80+
81+
* `parent`:父组件优先,滚动事件将先由父组件消费,剩余部分再由当前组件消费;
82+
83+
* `none`:不允许嵌套滚动,滚动事件将不会传递给父组件。
84+
85+
* nestedScrollPriority 默认值的说明:
86+
87+
如未设置任何滚动优先级时,iOS平台的默认值为`none`,即与系统默认行为保持一致。当指定任意一方向的优先级后,其他方向默认值为`self`
88+
Android平台默认值始终为`self`
7189

7290
* pointerEvents 的参数含义:
7391
* `auto`(默认值) - 视图可以是触摸事件的目标;
@@ -379,6 +397,24 @@ Hippy 的重点功能,高性能的可复用列表组件,在终端侧会被
379397
| endReached | 当所有的数据都已经渲染过,并且列表被滚动到最后一条时,将触发 `endReached` 回调。 | `Function` | `Android、iOS、Web-Renderer、Voltron` |
380398
| editable | 是否可编辑,开启侧滑删除时需要设置为 `true`。`最低支持版本2.9.0` | `boolean` | `iOS` |
381399
| delText | 侧滑删除文本。`最低支持版本2.9.0` | `string` | `iOS` |
400+
| nestedScrollPriority* | 嵌套滚动事件处理优先级,`default:self`。相当于同时设置 `nestedScrollLeftPriority`、 `nestedScrollTopPriority`、 `nestedScrollRightPriority`、 `nestedScrollBottomPriority`。 `Android最低支持版本 2.16.0,iOS最低支持版本3.3.3` | `enum(self,parent,none)` | `Android、iOS` |
401+
| nestedScrollLeftPriority | 嵌套时**从右往左**滚动事件的处理优先级,会覆盖 `nestedScrollPriority` 对应方向的值。`最低支持版本 2.16.0,iOS最低支持版本3.3.3` | `enum(self,parent,none)` | `Android、iOS` |
402+
| nestedScrollTopPriority | 嵌套时**从下往上**滚动事件的处理优先级,会覆盖 `nestedScrollPriority` 对应方向的值。`最低支持版本 2.16.0,iOS最低支持版本3.3.3` | `enum(self,parent,none)` | `Android、iOS` |
403+
| nestedScrollRightPriority | 嵌套时**从左往右**滚动事件的处理优先级,会覆盖 `nestedScrollPriority` 对应方向的值。`最低支持版本 2.16.0,iOS最低支持版本3.3.3` | `enum(self,parent,none)` | `Android、iOS` |
404+
| nestedScrollBottomPriority | 嵌套时**从上往下**滚动事件的处理优先级,会覆盖 `nestedScrollPriority` 对应方向的值。`最低支持版本 2.16.0,iOS最低支持版本3.3.3` | `enum(self,parent,none)` | `Android、iOS` |
405+
406+
* nestedScrollPriority 的参数含义:
407+
408+
* `self`(默认值):当前组件优先,滚动事件将先由当前组件消费,剩余部分传递给父组件消费;
409+
410+
* `parent`:父组件优先,滚动事件将先由父组件消费,剩余部分再由当前组件消费;
411+
412+
* `none`:不允许嵌套滚动,滚动事件将不会传递给父组件。
413+
414+
* nestedScrollPriority 默认值的说明:
415+
416+
如未设置任何滚动优先级时,iOS平台的默认值为`none`,即与系统默认行为保持一致。当指定任意一方向的优先级后,其他方向默认值为`self`;
417+
Android平台默认值始终为`self`。
382418

383419
## 事件
384420

renderer/native/ios/renderer/component/listview/HippyNextBaseListViewManager.m

+6
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ @implementation HippyNextBaseListViewManager
4646
HIPPY_EXPORT_VIEW_PROPERTY(showScrollIndicator, BOOL)
4747
HIPPY_EXPORT_VIEW_PROPERTY(scrollEnabled, BOOL)
4848
HIPPY_EXPORT_VIEW_PROPERTY(horizontal, BOOL)
49+
HIPPY_EXPORT_VIEW_PROPERTY(nestedScrollPriority, HippyNestedScrollPriority)
50+
HIPPY_EXPORT_VIEW_PROPERTY(nestedScrollTopPriority, HippyNestedScrollPriority)
51+
HIPPY_EXPORT_VIEW_PROPERTY(nestedScrollLeftPriority, HippyNestedScrollPriority)
52+
HIPPY_EXPORT_VIEW_PROPERTY(nestedScrollBottomPriority, HippyNestedScrollPriority)
53+
HIPPY_EXPORT_VIEW_PROPERTY(nestedScrollRightPriority, HippyNestedScrollPriority)
54+
4955

5056
- (UIView *)view {
5157
return [[HippyNextBaseListView alloc] init];

renderer/native/ios/renderer/component/listview/HippyNextListTableView.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222

2323
#import <UIKit/UIKit.h>
24+
#import "HippyNestedScrollProtocol.h"
2425

2526
NS_ASSUME_NONNULL_BEGIN
2627

@@ -35,8 +36,11 @@ NS_ASSUME_NONNULL_BEGIN
3536

3637
@end
3738

38-
@interface HippyNextListTableView : UICollectionView
3939

40+
/// Custom tableView (collectionView) of Hippy
41+
@interface HippyNextListTableView : UICollectionView <HippyNestedScrollProtocol>
42+
43+
/// Layout delegate
4044
@property (nonatomic, weak) id<HippyNextListTableViewLayoutProtocol> layoutDelegate;
4145

4246
@end

renderer/native/ios/renderer/component/listview/HippyNextListTableView.m

+12
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
@implementation HippyNextListTableView
2626

27+
HIPPY_NESTEDSCROLL_PROTOCOL_PROPERTY_IMP
28+
2729
/**
2830
* we need scroll indicator to be at top
2931
* indicator is UIImageView type at lower ios version
@@ -45,4 +47,14 @@ - (void)layoutSubviews {
4547
}
4648
}
4749

50+
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
51+
shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
52+
if (self.nestedGestureDelegate &&
53+
gestureRecognizer == self.panGestureRecognizer &&
54+
[self.nestedGestureDelegate respondsToSelector:@selector(shouldRecognizeScrollGestureSimultaneouslyWithView:)]) {
55+
return [self.nestedGestureDelegate shouldRecognizeScrollGestureSimultaneouslyWithView:otherGestureRecognizer.view];
56+
}
57+
return NO;
58+
}
59+
4860
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*!
2+
* iOS SDK
3+
*
4+
* Tencent is pleased to support the open source community by making
5+
* Hippy available.
6+
*
7+
* Copyright (C) 2019 THL A29 Limited, a Tencent company.
8+
* All rights reserved.
9+
*
10+
* Licensed under the Apache License, Version 2.0 (the "License");
11+
* you may not use this file except in compliance with the License.
12+
* You may obtain a copy of the License at
13+
*
14+
* http://www.apache.org/licenses/LICENSE-2.0
15+
*
16+
* Unless required by applicable law or agreed to in writing, software
17+
* distributed under the License is distributed on an "AS IS" BASIS,
18+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
* See the License for the specific language governing permissions and
20+
* limitations under the License.
21+
*/
22+
23+
#import <Foundation/Foundation.h>
24+
#import <UIKit/UIKit.h>
25+
#import "HippyScrollView.h"
26+
27+
NS_ASSUME_NONNULL_BEGIN
28+
29+
/// A coordinator responsible for managing scroll priorities
30+
@interface HippyNestedScrollCoordinator : NSObject <UIScrollViewDelegate, HippyNestedScrollGestureDelegate>
31+
32+
/// Priority of nestedScroll in all direction.
33+
@property (nonatomic, assign) HippyNestedScrollPriority nestedScrollPriority;
34+
/// Priority of nestedScroll in specific direction (finger move from bottom to top).
35+
@property (nonatomic, assign) HippyNestedScrollPriority nestedScrollTopPriority;
36+
/// Priority of nestedScroll in specific direction (finger move from right to left).
37+
@property (nonatomic, assign) HippyNestedScrollPriority nestedScrollLeftPriority;
38+
/// Priority of nestedScroll in specific direction (finger move from top to bottom).
39+
@property (nonatomic, assign) HippyNestedScrollPriority nestedScrollBottomPriority;
40+
/// Priority of nestedScroll in specific direction (finger move from left to right).
41+
@property (nonatomic, assign) HippyNestedScrollPriority nestedScrollRightPriority;
42+
43+
/// The inner scrollable view
44+
@property (nonatomic, weak) UIScrollView<HippyNestedScrollProtocol> *innerScrollView;
45+
/// The outer scrollable view
46+
@property (nonatomic, weak) UIScrollView<HippyNestedScrollProtocol> *outerScrollView;
47+
48+
@end
49+
50+
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)