Skip to content

Commit

Permalink
feat(android): add nestedScrollPriority for ListView and `ScrollV…
Browse files Browse the repository at this point in the history
…iew` (#2744)

* fix(android): nested scroll conflict

* fix(android): nested scroll conflicts with pull refresh

* feat(android): add `nestedScrollPriority` for ListView and ScrollView

* feat(android): squash branch scroll_conflict (#6)

* fix(android): nested scroll feature

  - edit priority api
  - scrollview prevent nested scroll when enabled paging
  - fix viewpager vertical issue
  - viewpager nested scroll
  - translate comments

* fix(android): Eltonqin/netscroll bugfix (#3)

* fix(android):HorizonScrollView may throw exception when handle onInterceptTouchEvent

* fix(android):post task still run after remove

* fix(android):post task still run after remove,modify format

Co-authored-by: eltonqin <[email protected]>

* fix(android): nested scroll feature

  - viewpager nested scroll issue

* feat(docs): update docs

Co-authored-by: HOHOHOTangoDown <[email protected]>
Co-authored-by: eltonqin <[email protected]>

* fix(android): nested scroll conflicts with pull refresh

* feat(docs, demo): update docs and demos

Co-authored-by: HOHOHOTangoDown <[email protected]>
Co-authored-by: eltonqin <[email protected]>

* fix(android): update scrollview consumed value

* refactor(js): perf nestedScrollPriority demo & docs (#9)

* refactor(js): perf nestedScrollPriority demo & docs

* refactor(js): add nested scroll more pager item

Co-authored-by: HOHOHOTangoDown <[email protected]>
Co-authored-by: eltonqin <[email protected]>
Co-authored-by: Zoom Chan <[email protected]>
  • Loading branch information
4 people authored Dec 7, 2022
1 parent 72ea6a5 commit 2644658
Show file tree
Hide file tree
Showing 24 changed files with 1,852 additions and 264 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import com.tencent.mtt.hippy.utils.LogUtils;
import com.tencent.mtt.hippy.utils.PixelUtil;
import com.tencent.mtt.hippy.views.common.CommonBorder;
import com.tencent.mtt.hippy.views.common.HippyNestedScrollComponent;
import com.tencent.mtt.hippy.views.common.HippyNestedScrollHelper;
import com.tencent.mtt.hippy.views.hippylist.HippyRecyclerViewWrapper;
import com.tencent.mtt.hippy.views.list.HippyListView;
import com.tencent.mtt.hippy.views.scroll.HippyScrollView;
Expand Down Expand Up @@ -640,6 +642,52 @@ public void setRenderToHardwareTexture(T view, boolean useHWTexture) {
view.setLayerType(useHWTexture ? View.LAYER_TYPE_HARDWARE : View.LAYER_TYPE_NONE, null);
}

@HippyControllerProps(name = HippyNestedScrollComponent.PROP_PRIORITY, defaultType =
HippyControllerProps.STRING, defaultString = HippyNestedScrollComponent.PRIORITY_SELF)
public void setNestedScrollPriority(T view, String priorityName) {
if (view instanceof HippyNestedScrollComponent) {
HippyNestedScrollComponent sc = (HippyNestedScrollComponent) view;
HippyNestedScrollComponent.Priority priority = HippyNestedScrollHelper.priorityOf(priorityName);
sc.setNestedScrollPriority(HippyNestedScrollComponent.DIRECTION_ALL, priority);
}
}

@HippyControllerProps(name = HippyNestedScrollComponent.PROP_LEFT_PRIORITY, defaultType =
HippyControllerProps.STRING, defaultString = HippyNestedScrollComponent.PRIORITY_SELF)
public void setNestedScrollLeftPriority(T view, String priorityName) {
if (view instanceof HippyNestedScrollComponent) {
HippyNestedScrollComponent.Priority priority = HippyNestedScrollHelper.priorityOf(priorityName);
((HippyNestedScrollComponent) view).setNestedScrollPriority(HippyNestedScrollComponent.DIRECTION_LEFT, priority);
}
}

@HippyControllerProps(name = HippyNestedScrollComponent.PROP_TOP_PRIORITY, defaultType =
HippyControllerProps.STRING, defaultString = HippyNestedScrollComponent.PRIORITY_SELF)
public void setNestedScrollTopPriority(T view, String priorityName) {
if (view instanceof HippyNestedScrollComponent) {
HippyNestedScrollComponent.Priority priority = HippyNestedScrollHelper.priorityOf(priorityName);
((HippyNestedScrollComponent) view).setNestedScrollPriority(HippyNestedScrollComponent.DIRECTION_TOP, priority);
}
}

@HippyControllerProps(name = HippyNestedScrollComponent.PROP_RIGHT_PRIORITY, defaultType =
HippyControllerProps.STRING, defaultString = HippyNestedScrollComponent.PRIORITY_SELF)
public void setNestedScrollRightPriority(T view, String priorityName) {
if (view instanceof HippyNestedScrollComponent) {
HippyNestedScrollComponent.Priority priority = HippyNestedScrollHelper.priorityOf(priorityName);
((HippyNestedScrollComponent) view).setNestedScrollPriority(HippyNestedScrollComponent.DIRECTION_RIGHT, priority);
}
}

@HippyControllerProps(name = HippyNestedScrollComponent.PROP_BOTTOM_PRIORITY, defaultType =
HippyControllerProps.STRING, defaultString = HippyNestedScrollComponent.PRIORITY_SELF)
public void setNestedScrollBottomPriority(T view, String priorityName) {
if (view instanceof HippyNestedScrollComponent) {
HippyNestedScrollComponent.Priority priority = HippyNestedScrollHelper.priorityOf(priorityName);
((HippyNestedScrollComponent) view).setNestedScrollPriority(HippyNestedScrollComponent.DIRECTION_BOTTOM, priority);
}
}

@SuppressWarnings("EmptyMethod")
@HippyControllerProps(name = NodeProps.CUSTOM_PROP)
public void setCustomProp(T view, String methodName, Object props) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* Tencent is pleased to support the open source community by making Hippy available.
* Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.tencent.mtt.hippy.views.common;

import androidx.core.view.NestedScrollingChild;
import androidx.core.view.NestedScrollingChild2;
import androidx.core.view.NestedScrollingParent;
import androidx.core.view.NestedScrollingParent2;

public interface HippyNestedScrollComponent {

String PROP_PRIORITY = "nestedScrollPriority";
String PROP_LEFT_PRIORITY = "nestedScrollLeftPriority";
String PROP_TOP_PRIORITY = "nestedScrollTopPriority";
String PROP_RIGHT_PRIORITY = "nestedScrollRightPriority";
String PROP_BOTTOM_PRIORITY = "nestedScrollBottomPriority";

String PRIORITY_PARENT = "parent";
String PRIORITY_SELF = "self";
String PRIORITY_NONE = "none";

int DIRECTION_INVALID = -1;
int DIRECTION_ALL = 0;
int DIRECTION_LEFT = 1;
int DIRECTION_TOP = 2;
int DIRECTION_RIGHT = 3;
int DIRECTION_BOTTOM = 4;

void setNestedScrollPriority(int direction, Priority priority);

Priority getNestedScrollPriority(int direction);

enum Priority {
NOT_SET,
PARENT,
SELF,
NONE,
}

/**
* Nested scroll interface declaration
*/
interface HippyNestedScrollTarget extends HippyNestedScrollComponent, NestedScrollingParent,
NestedScrollingChild {

}

/**
* Added non-touch scrolling type than {@link HippyNestedScrollTarget}
*/
interface HippyNestedScrollTarget2 extends HippyNestedScrollTarget, NestedScrollingParent2,
NestedScrollingChild2 {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/* Tencent is pleased to support the open source community by making Hippy available.
* Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.tencent.mtt.hippy.views.common;

import static com.tencent.mtt.hippy.views.common.HippyNestedScrollComponent.DIRECTION_BOTTOM;
import static com.tencent.mtt.hippy.views.common.HippyNestedScrollComponent.DIRECTION_LEFT;
import static com.tencent.mtt.hippy.views.common.HippyNestedScrollComponent.DIRECTION_RIGHT;
import static com.tencent.mtt.hippy.views.common.HippyNestedScrollComponent.DIRECTION_TOP;
import static com.tencent.mtt.hippy.views.common.HippyNestedScrollComponent.PRIORITY_NONE;
import static com.tencent.mtt.hippy.views.common.HippyNestedScrollComponent.PRIORITY_PARENT;
import static com.tencent.mtt.hippy.views.common.HippyNestedScrollComponent.PRIORITY_SELF;
import static com.tencent.mtt.hippy.views.common.HippyNestedScrollComponent.Priority;

import android.view.View;
import com.tencent.mtt.hippy.views.common.HippyNestedScrollComponent.HippyNestedScrollTarget;

public class HippyNestedScrollHelper {

public static Priority priorityOf(String name) {
switch (name) {
case PRIORITY_SELF:
return Priority.SELF;
case PRIORITY_PARENT:
return Priority.PARENT;
case PRIORITY_NONE:
return Priority.NONE;
default:
throw new RuntimeException("Invalid priority: " + name);
}
}

public static Priority priorityOfX(View target, int dx) {
// not scrolling, priority is NONE
if (dx == 0) {
return Priority.NONE;
}
// non-HippyNestedScrollTarget View, priority is SELF
if (!(target instanceof HippyNestedScrollTarget)) {
return Priority.SELF;
}
// get priority from target by direction
return ((HippyNestedScrollTarget) target).getNestedScrollPriority(
dx > 0 ? DIRECTION_LEFT : DIRECTION_RIGHT);
}

public static Priority priorityOfY(View target, int dy) {
// not scrolling, priority is NONE
if (dy == 0) {
return Priority.NONE;
}
// non-HippyNestedScrollTarget View, priority is SELF
if (!(target instanceof HippyNestedScrollTarget)) {
return Priority.SELF;
}
// get priority from target by direction
return ((HippyNestedScrollTarget) target).getNestedScrollPriority(
dy > 0 ? DIRECTION_TOP : DIRECTION_BOTTOM);
}
}
Loading

0 comments on commit 2644658

Please sign in to comment.