feat:Slider add scrollable

This commit is contained in:
pengfei.zhou 2021-04-23 17:55:59 +08:00 committed by osborn
parent c2ca3c0b31
commit 056f2f041f
3 changed files with 22 additions and 2 deletions

View File

@ -45,6 +45,7 @@ public class SliderNode extends SuperNode<RecyclerView> {
private String onPageSlidedFuncId;
private int lastPosition = 0;
private int itemCount = 0;
private boolean scrollable = true;
public SliderNode(DoricContext doricContext) {
super(doricContext);
@ -55,7 +56,15 @@ public class SliderNode extends SuperNode<RecyclerView> {
protected RecyclerView build() {
RecyclerView recyclerView = new RecyclerView(getContext());
final LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
final LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()) {
@Override
public boolean canScrollHorizontally() {
if (!scrollable) {
return false;
}
return super.canScrollHorizontally();
}
};
layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
recyclerView.setLayoutManager(layoutManager);
final PagerSnapHelper snapHelper = new PagerSnapHelper();
@ -146,6 +155,12 @@ public class SliderNode extends SuperNode<RecyclerView> {
@Override
protected void blend(RecyclerView view, String name, JSValue prop) {
switch (name) {
case "scrollable":
if (!prop.isBoolean()) {
return;
}
this.scrollable = prop.asBoolean().value();
break;
case "itemCount":
this.itemCount = prop.asNumber().toInt();
break;

View File

@ -75,7 +75,9 @@ - (UICollectionView *)build {
}
- (void)blendView:(UICollectionView *)view forPropName:(NSString *)name propValue:(id)prop {
if ([@"itemCount" isEqualToString:name]) {
if ([@"scrollable" isEqualToString:name]) {
self.view.scrollEnabled = [prop boolValue];
} else if ([@"itemCount" isEqualToString:name]) {
self.itemCount = [prop unsignedIntegerValue];
[self.view reloadData];
} else if ([@"renderPage" isEqualToString:name]) {

View File

@ -49,6 +49,9 @@ export class Slider extends Superview {
@Property
loop?: boolean
@Property
scrollable?: boolean
private getItem(itemIdx: number) {
let view = this.renderPage(itemIdx)
view.superview = this