iOS:change the way created item view.

This commit is contained in:
pengfei.zhou 2021-07-23 10:15:18 +08:00 committed by osborn
parent 05655972e3
commit f75a6f8071
4 changed files with 18 additions and 18 deletions

View File

@ -119,10 +119,10 @@ public class NavBarPlugin extends DoricJavaPlugin {
final JSObject jsObject = decoder.decode().asObject();
getDoricContext().getDriver().asyncCall(new Callable<Object>() {
@Override
public Object call() throws Exception {
public Object call() {
String viewId = jsObject.getProperty("id").asString().value();
String type = jsObject.getProperty("type").asString().value();
ViewNode node = ViewNode.create(getDoricContext(), type);
ViewNode<?> node = ViewNode.create(getDoricContext(), type);
node.setId(viewId);
node.init(new FrameLayout.LayoutParams(0, 0));
node.blend(jsObject.getProperty("props").asObject());
@ -162,10 +162,10 @@ public class NavBarPlugin extends DoricJavaPlugin {
final JSObject jsObject = decoder.decode().asObject();
getDoricContext().getDriver().asyncCall(new Callable<Object>() {
@Override
public Object call() throws Exception {
public Object call() {
String viewId = jsObject.getProperty("id").asString().value();
String type = jsObject.getProperty("type").asString().value();
ViewNode node = ViewNode.create(getDoricContext(), type);
ViewNode<?> node = ViewNode.create(getDoricContext(), type);
node.setId(viewId);
node.init(new FrameLayout.LayoutParams(0, 0));
node.blend(jsObject.getProperty("props").asObject());
@ -205,10 +205,10 @@ public class NavBarPlugin extends DoricJavaPlugin {
final JSObject jsObject = decoder.decode().asObject();
getDoricContext().getDriver().asyncCall(new Callable<Object>() {
@Override
public Object call() throws Exception {
public Object call() {
String viewId = jsObject.getProperty("id").asString().value();
String type = jsObject.getProperty("type").asString().value();
ViewNode node = ViewNode.create(getDoricContext(), type);
ViewNode<?> node = ViewNode.create(getDoricContext(), type);
node.setId(viewId);
node.init(new FrameLayout.LayoutParams(0, 0));
node.blend(jsObject.getProperty("props").asObject());

View File

@ -346,7 +346,7 @@ - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collection
[collectionView registerClass:[DoricFlowLayoutViewCell class] forCellWithReuseIdentifier:identifier];
DoricFlowLayoutViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
if (!cell.viewNode) {
DoricFlowLayoutItemNode *itemNode = [[DoricFlowLayoutItemNode alloc] initWithContext:self.doricContext];
DoricFlowLayoutItemNode *itemNode = (DoricFlowLayoutItemNode *) [DoricViewNode create:self.doricContext withType:@"FlowLayoutItem"];
[itemNode initWithSuperNode:self];
cell.viewNode = itemNode;
[cell.contentView addSubview:itemNode.view];

View File

@ -159,7 +159,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
DoricTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseId ?: @"doriccell"];
if (!cell) {
cell = [[DoricTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseId ?: @"doriccell"];
DoricListItemNode *listItemNode = [[DoricListItemNode alloc] initWithContext:self.doricContext];
DoricListItemNode *listItemNode = (DoricListItemNode *) [DoricViewNode create:self.doricContext withType:@"ListItem"];
[listItemNode initWithSuperNode:self];
cell.doricListItemNode = listItemNode;
cell.backgroundColor = [UIColor clearColor];

View File

@ -100,15 +100,15 @@ - (void)blendView:(UICollectionView *)view forPropName:(NSString *)name propValu
- (void)afterBlended:(NSDictionary *)props {
bool needToScroll = (self.propLoop && !self.loop)
|| (![self.renderPageFuncId isEqualToString: self.propRenderPageFuncId])
|| (self.itemCount == 0 && self.propItemCount > 0);
|| (![self.renderPageFuncId isEqualToString:self.propRenderPageFuncId])
|| (self.itemCount == 0 && self.propItemCount > 0);
// handle item count
if (self.itemCount != self.propItemCount) {
self.itemCount = self.propItemCount;
[self.view reloadData];
}
// handle render page
if ([self.renderPageFuncId isEqualToString:self.propRenderPageFuncId]) {
@ -118,15 +118,15 @@ - (void)afterBlended:(NSDictionary *)props {
[self.view reloadData];
self.renderPageFuncId = self.propRenderPageFuncId;
}
// handle loop
self.loop = self.propLoop;
__weak typeof(self) _self = self;
if (needToScroll) {
dispatch_async(dispatch_get_main_queue(), ^{
__strong typeof(_self) self = _self;
[self.view reloadData];
[self.view setContentOffset:CGPointMake(1 * self.view.width, self.view.contentOffset.y) animated:false];
});
@ -159,7 +159,7 @@ - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collection
NSDictionary *props = model[@"props"];
DoricSliderViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"doricCell" forIndexPath:indexPath];
if (!cell.doricSlideItemNode) {
DoricSlideItemNode *slideItemNode = [[DoricSlideItemNode alloc] initWithContext:self.doricContext];
DoricSlideItemNode *slideItemNode = (DoricSlideItemNode *) [DoricViewNode create:self.doricContext withType:@"SlideItem"];
[slideItemNode initWithSuperNode:self];
cell.doricSlideItemNode = slideItemNode;
[cell.contentView addSubview:slideItemNode.view];
@ -272,13 +272,13 @@ - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
- (void)slidePage:(NSDictionary *)params withPromise:(DoricPromise *)promise {
NSUInteger pageIndex = [params[@"page"] unsignedIntegerValue];
BOOL smooth = [params[@"smooth"] boolValue];
if (self.loop) {
[self.view setContentOffset:CGPointMake((pageIndex + 1) * self.view.width, self.view.contentOffset.y) animated:smooth];
} else {
[self.view setContentOffset:CGPointMake(pageIndex * self.view.width, self.view.contentOffset.y) animated:smooth];
}
[promise resolve:nil];
self.lastPosition = pageIndex;
if (self.onPageSelectedFuncId && self.onPageSelectedFuncId.length > 0) {