Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android): add nestedScrollPriority for ListView and ScrollView #2744

Merged
merged 7 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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