feat:Pullable return pulling distance

This commit is contained in:
pengfei.zhou 2019-12-02 21:01:34 +08:00
parent 35fe6c41d5
commit 2e96912a99
12 changed files with 83 additions and 58 deletions

View File

@ -21,7 +21,7 @@ public class DoricRefreshView extends FrameLayout implements PullingListener {
private View content;
private Animation.AnimationListener mListener;
private PullingListener mPullingListenr;
private PullingListener mPullingListener;
public DoricRefreshView(@NonNull Context context) {
super(context);
@ -38,12 +38,15 @@ public class DoricRefreshView extends FrameLayout implements PullingListener {
public void setContent(View v) {
removeAllViews();
content = v;
if (v.getLayoutParams() instanceof FrameLayout.LayoutParams) {
((LayoutParams) v.getLayoutParams()).gravity = Gravity.BOTTOM;
ViewGroup.LayoutParams params = v.getLayoutParams();
if (params instanceof LayoutParams) {
((LayoutParams) params).gravity = Gravity.BOTTOM;
} else {
LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.CENTER;
v.setLayoutParams(params);
LayoutParams layoutParams = new LayoutParams(
params == null ? ViewGroup.LayoutParams.WRAP_CONTENT : params.width,
params == null ? ViewGroup.LayoutParams.WRAP_CONTENT : params.height);
layoutParams.gravity = Gravity.CENTER;
v.setLayoutParams(layoutParams);
}
addView(v);
}
@ -53,28 +56,28 @@ public class DoricRefreshView extends FrameLayout implements PullingListener {
}
public void setPullingListenr(PullingListener listenr) {
this.mPullingListenr = listenr;
public void setPullingListener(PullingListener listener) {
this.mPullingListener = listener;
}
@Override
public void startAnimation() {
if (mPullingListenr != null) {
mPullingListenr.startAnimation();
if (mPullingListener != null) {
mPullingListener.startAnimation();
}
}
@Override
public void stopAnimation() {
if (mPullingListenr != null) {
mPullingListenr.stopAnimation();
if (mPullingListener != null) {
mPullingListener.stopAnimation();
}
}
@Override
public void setProgressRotation(float rotation) {
if (mPullingListenr != null) {
mPullingListenr.setProgressRotation(rotation);
public void setPullingDistance(float distance) {
if (mPullingListener != null) {
mPullingListener.setPullingDistance(distance);
}
}

View File

@ -912,7 +912,7 @@ public class DoricSwipeLayout extends ViewGroup implements NestedScrollingParent
ViewCompat.offsetTopAndBottom(mRefreshView, offset);
mCurrentTargetOffsetTop = mRefreshView.getTop();
if (mRefreshView.getMeasuredHeight() > 0) {
mRefreshView.setProgressRotation((float) mRefreshView.getBottom() / (float) mRefreshView.getMeasuredHeight() * 2);
mRefreshView.setPullingDistance((float) mRefreshView.getBottom());
}
}

View File

@ -16,5 +16,5 @@ public interface PullingListener {
*
* @param rotation Rotation is from [0..2]
*/
void setProgressRotation(float rotation);
void setPullingDistance(float rotation);
}

View File

@ -33,7 +33,7 @@ public class RefreshableNode extends SuperNode<DoricSwipeLayout> implements Pull
@Override
protected DoricSwipeLayout build() {
DoricSwipeLayout doricSwipeLayout = new DoricSwipeLayout(getContext());
doricSwipeLayout.getRefreshView().setPullingListenr(this);
doricSwipeLayout.getRefreshView().setPullingListener(this);
return doricSwipeLayout;
}
@ -188,9 +188,9 @@ public class RefreshableNode extends SuperNode<DoricSwipeLayout> implements Pull
}
@Override
public void setProgressRotation(float rotation) {
public void setPullingDistance(float rotation) {
if (mHeaderNode != null) {
mHeaderNode.callJSResponse("setProgressRotation", rotation);
mHeaderNode.callJSResponse("setPullingDistance", rotation);
}
}
}

View File

@ -17,4 +17,5 @@ export default [
'src/PopoverDemo',
'src/AnimatorDemo',
'src/ComplicatedAnimations',
'src/ComplicatedDemo',
]

View File

@ -0,0 +1,48 @@
import { Panel, Group, vlayout, image, layoutConfig, ScaleType, refreshable, Color, pullable, stack, Image, Refreshable, TranslationAnimation } from "doric";
import { title, icon_refresh } from "./utils";
@Entry
class MyDemo extends Panel {
build(root: Group) {
let refreshed: Refreshable
let headerImage: Image
stack([
refreshed = refreshable({
onRefresh: () => {
refreshed.setRefreshing(context, false)
},
header: pullable(context,
stack([]).apply({
backgroundColor: Color.RED,
layoutConfig: layoutConfig().exactly(),
width: 100,
height: 30,
}),
{
startAnimation: () => {
},
stopAnimation: () => {
},
setPullingDistance: (rotation: number) => {
headerImage.scaleX = headerImage.scaleY = (headerImage.height + rotation) / headerImage.height
},
}),
content: vlayout([]).apply({
backgroundColor: Color.YELLOW,
}),
}).apply({
layoutConfig: layoutConfig().atmost(),
}).also(v => {
v.top = 200
}),
headerImage = image({
imageUrl: "https://img.zcool.cn/community/01e75b5da933daa801209e1ffa4649.jpg@1280w_1l_2o_100sh.jpg",
layoutConfig: layoutConfig().exactly(),
width: root.width,
height: 200,
scaleType: ScaleType.ScaleAspectFill,
}),
]).in(root)
}
}

View File

@ -31,8 +31,8 @@ class RefreshableDemo extends Panel {
stopAnimation: () => {
log('stopAnimation')
},
setProgressRotation: (rotation: number) => {
refreshImage.rotation = rotation
setPullingDistance: (distance: number) => {
refreshImage.rotation = distance / 30
},
}),
content: (vlayout([
@ -83,18 +83,6 @@ class RefreshableDemo extends Panel {
refreshView.setRefreshable(context, false)
}
} as IText),
label('Rotate self').apply({
width: 300,
height: 50,
backgroundColor: colors[0],
textSize: 30,
textColor: Color.WHITE,
layoutConfig: layoutConfig().exactly(),
} as IText).also(v => {
v.onClick = () => {
v.nativeChannel(context, "setRotation")(0.25)
}
}),
]).apply({
layoutConfig: layoutConfig().atmost().h(LayoutSpec.WRAP_CONTENT),
gravity: gravity().centerX(),

View File

@ -65,8 +65,8 @@ export function rotatedArrow(context: BridgeContext) {
stopAnimation: () => {
log('stopAnimation')
},
setProgressRotation: (rotation: number) => {
refreshImage.rotation = rotation
setPullingDistance: (distance: number) => {
refreshImage.rotation = distance / 30
},
})
}

View File

@ -152,8 +152,8 @@ - (void)stopAnimation {
[self.headerNode callJSResponse:@"stopAnimation", nil];
}
- (void)setProgressRotation:(CGFloat)rotation {
[self.headerNode callJSResponse:@"setProgressRotation", @(rotation), nil];
- (void)setPullingDistance:(CGFloat)distance {
[self.headerNode callJSResponse:@"setPullingDistance", @(distance), nil];
}
- (void)setRefreshing:(NSNumber *)refreshable withPromise:(DoricPromise *)promise {

View File

@ -1,18 +1,3 @@
/*
* Copyright [2019] [Doric.Pub]
*
* 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.
*/
//
// Created by pengfei.zhou on 2019/11/26.
//
@ -24,7 +9,7 @@
- (void)stopAnimation;
- (void)setProgressRotation:(CGFloat)rotation;
- (void)setPullingDistance:(CGFloat)rotation;
@end
@interface DoricSwipeRefreshLayout : UIScrollView

View File

@ -109,7 +109,7 @@ - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView.contentOffset.y <= 0) {
[self.swipePullingDelegate setProgressRotation:-scrollView.contentOffset.y / self.headerView.height * 2];
[self.swipePullingDelegate setPullingDistance:-scrollView.contentOffset.y];
}
}

View File

@ -62,13 +62,13 @@ export function refreshable(config: IRefreshable) {
export interface IPullable {
startAnimation(): void
stopAnimation(): void
setProgressRotation(rotation: number): void
setPullingDistance(distance: number): void
}
export function pullable(context: BridgeContext, v: View, config: IPullable) {
Reflect.set(v, 'startAnimation', config.startAnimation)
Reflect.set(v, 'stopAnimation', config.stopAnimation)
Reflect.set(v, 'setProgressRotation', config.setProgressRotation)
Reflect.set(v, 'setPullingDistance', config.setPullingDistance)
return v
}