bugfix: slider need scroll logic

This commit is contained in:
王劲鹏 2022-06-20 18:52:35 +08:00 committed by osborn
parent d405f60c7f
commit 4cfb7b4076
2 changed files with 16 additions and 5 deletions

View File

@ -173,7 +173,8 @@ public class SliderNode extends SuperNode<RecyclerView> {
mView.post(new Runnable() { mView.post(new Runnable() {
@Override @Override
public void run() { public void run() {
mView.scrollToPosition(1); int position = slideAdapter.loop ? 1 : 0;
mView.scrollToPosition(position);
} }
}); });
} }

View File

@ -37,11 +37,12 @@ @interface DoricSliderNode () <UICollectionViewDataSource, UICollectionViewDeleg
@property(nonatomic, assign) NSUInteger propItemCount; @property(nonatomic, assign) NSUInteger propItemCount;
@property(nonatomic, assign) NSUInteger batchCount; @property(nonatomic, assign) NSUInteger batchCount;
@property(nonatomic, copy) NSString *onPageSelectedFuncId; @property(nonatomic, copy) NSString *onPageSelectedFuncId;
@property(nonatomic) BOOL loop; @property(nonatomic, assign) BOOL loop;
@property(nonatomic) BOOL propLoop; @property(nonatomic, assign) BOOL propLoop;
@property(nonatomic, assign) NSUInteger lastPosition; @property(nonatomic, assign) NSUInteger lastPosition;
@property(nonatomic, copy) NSString *renderPageFuncId; @property(nonatomic, copy) NSString *renderPageFuncId;
@property(nonatomic, copy) NSString *propRenderPageFuncId; @property(nonatomic, copy) NSString *propRenderPageFuncId;
@property(nonatomic, assign) BOOL needResetScroll;
@end @end
@interface DoricSliderView : UICollectionView @interface DoricSliderView : UICollectionView
@ -101,7 +102,8 @@ - (void)blendView:(UICollectionView *)view forPropName:(NSString *)name propValu
- (void)afterBlended:(NSDictionary *)props { - (void)afterBlended:(NSDictionary *)props {
bool needToScroll = (self.propLoop && !self.loop) bool needToScroll = (self.propLoop && !self.loop)
|| (![self.renderPageFuncId isEqualToString:self.propRenderPageFuncId]) || (![self.renderPageFuncId isEqualToString:self.propRenderPageFuncId])
|| (self.itemCount == 0 && self.propItemCount > 0); || (self.itemCount == 0 && self.propItemCount > 0)
|| self.needResetScroll;
// handle item count // handle item count
if (self.itemCount != self.propItemCount) { if (self.itemCount != self.propItemCount) {
@ -122,13 +124,21 @@ - (void)afterBlended:(NSDictionary *)props {
// handle loop // handle loop
self.loop = self.propLoop; self.loop = self.propLoop;
__weak typeof(self) _self = self; __weak typeof(self) _self = self;
if (needToScroll) { if (needToScroll) {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
__strong typeof(_self) self = _self; __strong typeof(_self) self = _self;
[self.view reloadData]; [self.view reloadData];
[self.view setContentOffset:CGPointMake(1 * self.view.width, self.view.contentOffset.y) animated:false];
int position = self.loop ? 1 : 0;
if (self.view.width == 0) {
self.needResetScroll = true;
} else {
self.needResetScroll = false;
[self.view setContentOffset:CGPointMake(position * self.view.width, self.view.contentOffset.y) animated:false];
}
}); });
} }
} }