feature:CoordinateLayout support multi set
This commit is contained in:
parent
eceb7b9567
commit
01d736c5a6
@ -21,5 +21,7 @@ package pub.doric;
|
||||
* @CreateDate: 2020-02-13
|
||||
*/
|
||||
public interface IDoricScrollable {
|
||||
void setScrollChangeListener(DoricScrollChangeListener listener);
|
||||
void addScrollChangeListener(DoricScrollChangeListener listener);
|
||||
|
||||
void removeScrollChangeListener(DoricScrollChangeListener listener);
|
||||
}
|
||||
|
@ -119,8 +119,7 @@ public class CoordinatorPlugin extends DoricJavaPlugin {
|
||||
final boolean finalIsNavBar = isNavBar;
|
||||
|
||||
if (finalScrollNode instanceof IDoricScrollable) {
|
||||
|
||||
((IDoricScrollable) finalScrollNode).setScrollChangeListener(new DoricScrollChangeListener() {
|
||||
((IDoricScrollable) finalScrollNode).addScrollChangeListener(new DoricScrollChangeListener() {
|
||||
@Override
|
||||
public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
|
||||
if (scrollY <= startAnchor) {
|
||||
|
@ -22,6 +22,9 @@ import com.github.pengfeizhou.jscore.JSONBuilder;
|
||||
import com.github.pengfeizhou.jscore.JSObject;
|
||||
import com.github.pengfeizhou.jscore.JSValue;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.DoricScrollChangeListener;
|
||||
import pub.doric.IDoricScrollable;
|
||||
@ -39,7 +42,7 @@ import pub.doric.widget.HVScrollView;
|
||||
public class ScrollerNode extends SuperNode<HVScrollView> implements IDoricScrollable {
|
||||
private String mChildViewId;
|
||||
private ViewNode mChildNode;
|
||||
private DoricScrollChangeListener doricScrollChangeListener;
|
||||
private Set<DoricScrollChangeListener> listeners = new HashSet<>();
|
||||
private String onScrollFuncId;
|
||||
private String onScrollEndFuncId;
|
||||
|
||||
@ -67,8 +70,8 @@ public class ScrollerNode extends SuperNode<HVScrollView> implements IDoricScrol
|
||||
|
||||
@Override
|
||||
public void onScrollChange(HVScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
|
||||
if (doricScrollChangeListener != null) {
|
||||
doricScrollChangeListener.onScrollChange(v, scrollX, scrollY, oldScrollX, oldScrollY);
|
||||
for (DoricScrollChangeListener listener : listeners) {
|
||||
listener.onScrollChange(v, scrollX, scrollY, oldScrollX, oldScrollY);
|
||||
}
|
||||
if (!TextUtils.isEmpty(onScrollFuncId)) {
|
||||
callJSResponse(onScrollFuncId, new JSONBuilder()
|
||||
@ -147,8 +150,13 @@ public class ScrollerNode extends SuperNode<HVScrollView> implements IDoricScrol
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScrollChangeListener(DoricScrollChangeListener listener) {
|
||||
this.doricScrollChangeListener = listener;
|
||||
public void addScrollChangeListener(DoricScrollChangeListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeScrollChangeListener(DoricScrollChangeListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
@DoricMethod
|
||||
|
@ -26,6 +26,9 @@ import androidx.recyclerview.widget.StaggeredGridLayoutManager;
|
||||
import com.github.pengfeizhou.jscore.JSObject;
|
||||
import com.github.pengfeizhou.jscore.JSValue;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.DoricScrollChangeListener;
|
||||
import pub.doric.IDoricScrollable;
|
||||
@ -76,7 +79,7 @@ public class FlowLayoutNode extends SuperNode<RecyclerView> implements IDoricScr
|
||||
String onLoadMoreFuncId;
|
||||
boolean loadMore = false;
|
||||
String loadMoreViewId;
|
||||
private DoricScrollChangeListener doricScrollChangeListener;
|
||||
private Set<DoricScrollChangeListener> listeners = new HashSet<>();
|
||||
|
||||
public FlowLayoutNode(DoricContext doricContext) {
|
||||
super(doricContext);
|
||||
@ -201,18 +204,24 @@ public class FlowLayoutNode extends SuperNode<RecyclerView> implements IDoricScr
|
||||
@Override
|
||||
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
||||
super.onScrolled(recyclerView, dx, dy);
|
||||
if (doricScrollChangeListener != null) {
|
||||
for (DoricScrollChangeListener listener : listeners) {
|
||||
int offsetX = recyclerView.computeHorizontalScrollOffset();
|
||||
int offsetY = recyclerView.computeVerticalScrollOffset();
|
||||
doricScrollChangeListener.onScrollChange(recyclerView, offsetX, offsetY, offsetX - dx, offsetY - dy);
|
||||
listener.onScrollChange(recyclerView, offsetX, offsetY, offsetX - dx, offsetY - dy);
|
||||
}
|
||||
}
|
||||
});
|
||||
return recyclerView;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setScrollChangeListener(DoricScrollChangeListener listener) {
|
||||
this.doricScrollChangeListener = listener;
|
||||
public void addScrollChangeListener(DoricScrollChangeListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeScrollChangeListener(DoricScrollChangeListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,9 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.github.pengfeizhou.jscore.JSObject;
|
||||
import com.github.pengfeizhou.jscore.JSValue;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.DoricScrollChangeListener;
|
||||
import pub.doric.IDoricScrollable;
|
||||
@ -48,7 +51,7 @@ public class ListNode extends SuperNode<RecyclerView> implements IDoricScrollabl
|
||||
SparseArray<String> itemValues = new SparseArray<>();
|
||||
boolean loadMore = false;
|
||||
String loadMoreViewId;
|
||||
private DoricScrollChangeListener doricScrollChangeListener;
|
||||
private Set<DoricScrollChangeListener> listeners = new HashSet<>();
|
||||
|
||||
public ListNode(DoricContext doricContext) {
|
||||
super(doricContext);
|
||||
@ -79,10 +82,10 @@ public class ListNode extends SuperNode<RecyclerView> implements IDoricScrollabl
|
||||
@Override
|
||||
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
||||
super.onScrolled(recyclerView, dx, dy);
|
||||
if (doricScrollChangeListener != null) {
|
||||
for (DoricScrollChangeListener listener : listeners) {
|
||||
int offsetX = recyclerView.computeHorizontalScrollOffset();
|
||||
int offsetY = recyclerView.computeVerticalScrollOffset();
|
||||
doricScrollChangeListener.onScrollChange(recyclerView, offsetX, offsetY, offsetX - dx, offsetY - dy);
|
||||
listener.onScrollChange(recyclerView, offsetX, offsetY, offsetX - dx, offsetY - dy);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -162,7 +165,12 @@ public class ListNode extends SuperNode<RecyclerView> implements IDoricScrollabl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScrollChangeListener(DoricScrollChangeListener listener) {
|
||||
this.doricScrollChangeListener = listener;
|
||||
public void addScrollChangeListener(DoricScrollChangeListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeScrollChangeListener(DoricScrollChangeListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,11 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricScrollableProtocol.h"
|
||||
|
||||
typedef void (^DoricDidScrollBlock)(UIScrollView *__nonnull scrollView);
|
||||
|
||||
@protocol DoricScrollableProtocol <NSObject>
|
||||
@property(nonatomic, strong, nullable) void (^didScrollListener)(UIScrollView *__nonnull scrollView);
|
||||
|
||||
- (void)addDidScrollBlock:(__nonnull DoricDidScrollBlock)didScrollListener;
|
||||
|
||||
- (void)removeDidScrollBlock:(__nonnull DoricDidScrollBlock)didScrollListener;
|
||||
@end
|
||||
|
@ -22,5 +22,4 @@
|
||||
#import "DoricScrollableProtocol.h"
|
||||
|
||||
@interface DoricFlowLayoutNode : DoricSuperNode<UICollectionView *> <DoricScrollableProtocol>
|
||||
@property(nonatomic, strong, nullable) void (^didScrollListener)(UIScrollView *__nonnull scrollView);
|
||||
@end
|
@ -171,6 +171,7 @@ @interface DoricFlowLayoutNode () <UICollectionViewDataSource, UICollectionViewD
|
||||
@property(nonatomic, copy) NSString *onLoadMoreFuncId;
|
||||
@property(nonatomic, copy) NSString *loadMoreViewId;
|
||||
@property(nonatomic, assign) BOOL loadMore;
|
||||
@property(nonatomic, strong) NSMutableSet <DoricDidScrollBlock> *didScrollBlocks;
|
||||
@end
|
||||
|
||||
@implementation DoricFlowLayoutNode
|
||||
@ -370,8 +371,23 @@ - (NSInteger)doricFlowLayoutColumnCount {
|
||||
}
|
||||
|
||||
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
|
||||
if (self.didScrollListener) {
|
||||
self.didScrollListener(scrollView);
|
||||
for (DoricDidScrollBlock block in self.didScrollBlocks) {
|
||||
block(scrollView);
|
||||
}
|
||||
}
|
||||
|
||||
- (NSMutableSet<DoricDidScrollBlock> *)didScrollBlocks {
|
||||
if (!_didScrollBlocks) {
|
||||
_didScrollBlocks = [NSMutableSet new];
|
||||
}
|
||||
return _didScrollBlocks;
|
||||
}
|
||||
|
||||
- (void)addDidScrollBlock:(__nonnull DoricDidScrollBlock)didScrollListener {
|
||||
[self.didScrollBlocks addObject:didScrollListener];
|
||||
}
|
||||
|
||||
- (void)removeDidScrollBlock:(__nonnull DoricDidScrollBlock)didScrollListener {
|
||||
[self.didScrollBlocks removeObject:didScrollListener];
|
||||
}
|
||||
@end
|
||||
|
@ -22,5 +22,4 @@
|
||||
#import "DoricScrollableProtocol.h"
|
||||
|
||||
@interface DoricListNode : DoricSuperNode<UITableView *> <DoricScrollableProtocol>
|
||||
@property(nonatomic, strong, nullable) void (^didScrollListener)(UIScrollView *__nonnull scrollView);
|
||||
@end
|
@ -66,6 +66,7 @@ @interface DoricListNode () <UITableViewDataSource, UITableViewDelegate>
|
||||
@property(nonatomic, copy) NSString *renderItemFuncId;
|
||||
@property(nonatomic, copy) NSString *loadMoreViewId;
|
||||
@property(nonatomic, assign) BOOL loadMore;
|
||||
@property(nonatomic, strong) NSMutableSet <DoricDidScrollBlock> *didScrollBlocks;
|
||||
@end
|
||||
|
||||
@implementation DoricListNode
|
||||
@ -250,8 +251,24 @@ - (DoricViewNode *)subNodeWithViewId:(NSString *)viewId {
|
||||
}
|
||||
|
||||
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
|
||||
if (self.didScrollListener) {
|
||||
self.didScrollListener(scrollView);
|
||||
for (DoricDidScrollBlock block in self.didScrollBlocks) {
|
||||
block(scrollView);
|
||||
}
|
||||
}
|
||||
|
||||
- (NSMutableSet<DoricDidScrollBlock> *)didScrollBlocks {
|
||||
if (!_didScrollBlocks) {
|
||||
_didScrollBlocks = [NSMutableSet new];
|
||||
}
|
||||
return _didScrollBlocks;
|
||||
}
|
||||
|
||||
- (void)addDidScrollBlock:(__nonnull DoricDidScrollBlock)didScrollListener {
|
||||
[self.didScrollBlocks addObject:didScrollListener];
|
||||
}
|
||||
|
||||
- (void)removeDidScrollBlock:(__nonnull DoricDidScrollBlock)didScrollListener {
|
||||
[self.didScrollBlocks removeObject:didScrollListener];
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -28,5 +28,4 @@
|
||||
@end
|
||||
|
||||
@interface DoricScrollerNode : DoricSuperNode<DoricScrollView *> <DoricScrollableProtocol>
|
||||
@property(nonatomic, strong, nullable) void (^didScrollListener)(UIScrollView *__nonnull scrollView);
|
||||
@end
|
@ -53,6 +53,7 @@ @interface DoricScrollerNode () <UIScrollViewDelegate>
|
||||
@property(nonatomic, copy) NSString *childViewId;
|
||||
@property(nonatomic, copy) NSString *onScrollFuncId;
|
||||
@property(nonatomic, copy) NSString *onScrollEndFuncId;
|
||||
@property(nonatomic, strong) NSMutableSet <DoricDidScrollBlock> *didScrollBlocks;
|
||||
@end
|
||||
|
||||
@implementation DoricScrollerNode
|
||||
@ -139,8 +140,8 @@ - (DoricViewNode *)subNodeWithViewId:(NSString *)viewId {
|
||||
}
|
||||
|
||||
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
|
||||
if (self.didScrollListener) {
|
||||
self.didScrollListener(scrollView);
|
||||
for (DoricDidScrollBlock block in self.didScrollBlocks) {
|
||||
block(scrollView);
|
||||
}
|
||||
if (self.onScrollFuncId) {
|
||||
[self callJSResponse:self.onScrollFuncId,
|
||||
@ -192,4 +193,20 @@ - (void)scrollBy:(NSDictionary *)params {
|
||||
MIN(self.view.contentSize.height - self.view.height, MAX(0, offset.y + self.view.contentOffset.y)))
|
||||
animated:animated];
|
||||
}
|
||||
|
||||
- (NSMutableSet<DoricDidScrollBlock> *)didScrollBlocks {
|
||||
if (!_didScrollBlocks) {
|
||||
_didScrollBlocks = [NSMutableSet new];
|
||||
}
|
||||
return _didScrollBlocks;
|
||||
}
|
||||
|
||||
- (void)addDidScrollBlock:(__nonnull DoricDidScrollBlock)didScrollListener {
|
||||
[self.didScrollBlocks addObject:didScrollListener];
|
||||
}
|
||||
|
||||
- (void)removeDidScrollBlock:(__nonnull DoricDidScrollBlock)didScrollListener {
|
||||
[self.didScrollBlocks removeObject:didScrollListener];
|
||||
}
|
||||
|
||||
@end
|
||||
|
Reference in New Issue
Block a user