Skip to content

Commit 250399a

Browse files
committed
Merge branch 'master' of github.com:apache/incubator-weex
2 parents db67f83 + 2c78b65 commit 250399a

17 files changed

+302
-115
lines changed

android/sdk/assets/weex-main-jsfm.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

android/sdk/src/main/java/com/taobao/weex/ui/RenderContextImpl.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
*/
1919
package com.taobao.weex.ui;
2020

21-
import android.support.v4.util.ArrayMap;
22-
import android.util.Log;
23-
2421
import com.taobao.weex.WXSDKInstance;
2522
import com.taobao.weex.dom.RenderContext;
2623
import com.taobao.weex.ui.component.WXComponent;
@@ -31,6 +28,7 @@
3128
import java.util.List;
3229
import java.util.Map;
3330
import java.util.Set;
31+
import java.util.concurrent.ConcurrentHashMap;
3432

3533
/**
3634
* Class for rendering view. Method in this class should be run in main thread.
@@ -43,7 +41,7 @@ class RenderContextImpl implements RenderContext {
4341

4442
public RenderContextImpl(WXSDKInstance instance) {
4543
mWXSDKInstance = instance;
46-
mRegistry = new ArrayMap<>();
44+
mRegistry = new ConcurrentHashMap<>();
4745
}
4846

4947
public void destroy() {

android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public void setIndex(int index){
159159
public void executeAction() {
160160
super.executeAction();
161161
try {
162-
if (!TextUtils.equals("mComponentType", "video") && !TextUtils.equals("mComponentType", "videoplus"))
162+
if (!TextUtils.equals(mComponentType, "video") && !TextUtils.equals(mComponentType, "videoplus"))
163163
child.mIsAddElementToTree = true;
164164

165165
parent.addChild(child, mIndex);

android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionMoveElement.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void executeAction() {
4545
return;
4646
}
4747

48-
if (component.getHostView() != null && !TextUtils.equals("mComponentType", "video") && !TextUtils.equals("mComponentType", "videoplus")) {
48+
if (component.getHostView() != null && !TextUtils.equals(component.getComponentType(), "video") && !TextUtils.equals(component.getComponentType(), "videoplus")) {
4949
int[] location = new int[2] ;
5050
component.getHostView().getLocationInWindow(location);
5151
component.getInstance().onChangeElement(oldParent, location[1] > component.getInstance().getWeexHeight() + 1);
@@ -55,7 +55,7 @@ public void executeAction() {
5555

5656
((WXVContainer) newParent).addChild(component, mIndex);
5757

58-
if (component.getHostView() != null && !TextUtils.equals("mComponentType", "video") && !TextUtils.equals("mComponentType", "videoplus")) {
58+
if (component.getHostView() != null && !TextUtils.equals(component.getComponentType(), "video") && !TextUtils.equals(component.getComponentType(), "videoplus")) {
5959
int[] location = new int[2] ;
6060
component.getHostView().getLocationInWindow(location);
6161
component.getInstance().onChangeElement(newParent, location[1] > component.getInstance().getWeexHeight() + 1);

android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRemoveElement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void executeAction() {
3838
clearRegistryForComponent(component);
3939
WXVContainer parent = component.getParent();
4040

41-
if (component.getHostView() != null && !TextUtils.equals("mComponentType", "video") && !TextUtils.equals("mComponentType", "videoplus")) {
41+
if (component.getHostView() != null && !TextUtils.equals(component.getComponentType(), "video") && !TextUtils.equals(component.getComponentType(), "videoplus")) {
4242
int[] location = new int[2];
4343
component.getHostView().getLocationInWindow(location);
4444
component.getInstance().onChangeElement(parent, location[1] > component.getInstance().getWeexHeight() + 1);

android/sdk/src/main/java/com/taobao/weex/ui/component/WXImage.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
*/
1919
package com.taobao.weex.ui.component;
2020

21+
import android.support.annotation.RestrictTo;
22+
import android.support.annotation.RestrictTo.Scope;
23+
import com.taobao.weex.dom.WXImageQuality;
2124
import java.lang.reflect.InvocationTargetException;
2225
import java.util.Arrays;
2326
import java.util.HashMap;
@@ -159,7 +162,8 @@ public void setResizeMode(String resizeMode) {
159162
(getHostView()).setScaleType(getResizeMode(resizeMode));
160163
}
161164

162-
private ScaleType getResizeMode(String resizeMode) {
165+
@RestrictTo(Scope.LIBRARY_GROUP)
166+
protected ScaleType getResizeMode(String resizeMode) {
163167
ScaleType scaleType = ScaleType.FIT_XY;
164168
if (TextUtils.isEmpty(resizeMode)) {
165169
return scaleType;
@@ -337,10 +341,15 @@ public void onImageFinish(String url, ImageView imageView, boolean result, Map e
337341
IWXImgLoaderAdapter imgLoaderAdapter = getInstance().getImgLoaderAdapter();
338342
if (imgLoaderAdapter != null) {
339343
imgLoaderAdapter.setImage(rewrited.toString(), getHostView(),
340-
getAttrs().getImageQuality(), imageStrategy);
344+
getImageQuality(), imageStrategy);
341345
}
342346
}
343347

348+
@RestrictTo(Scope.LIBRARY_GROUP)
349+
protected WXImageQuality getImageQuality(){
350+
return getAttrs().getImageQuality();
351+
}
352+
344353
@Override
345354
protected void onFinishLayout() {
346355
super.onFinishLayout();

ios/sdk/WeexSDK/Sources/Component/RecycleList/WXCellSlotComponent.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ static const NSString *WXDefaultRecycleTemplateType = @"default";
2626
@property (nonatomic, strong) NSString *templateCaseType;
2727

2828
- (void)updateCellData:(NSDictionary *)data;
29-
3029
- (void)triggerLayout;
3130

32-
3331
@end

ios/sdk/WeexSDK/Sources/Component/RecycleList/WXCellSlotComponent.mm

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ - (instancetype)initWithRef:(NSString *)ref
4040
if (attributes[@"default"]) {
4141
_templateCaseType = @"default";
4242
}
43-
_templateCaseType = attributes[@"case"] ? [WXConvert NSString:attributes[@"case"]] :const_cast<NSString *>(WXDefaultRecycleTemplateType) ;
43+
_templateCaseType = attributes[@"case"] ? [WXConvert NSString:attributes[@"case"]] :const_cast<NSString *>(WXDefaultRecycleTemplateType);
4444
_lazyCreateView = YES;
4545
_isNeedJoinLayoutSystem = NO;
4646
}
@@ -55,9 +55,9 @@ - (void)updateAttributes:(NSDictionary *)attributes
5555

5656
- (void)updateCellData:(NSDictionary *)data
5757
{
58-
WXAssertComponentThread();
59-
58+
WXAssertComponentThread();
6059
[self updateBindingData:data];
60+
[self _attachSlotEvent:data];
6161
[self triggerLayout];
6262
}
6363

@@ -69,21 +69,16 @@ - (void)_didInserted
6969
- (void)triggerLayout
7070
{
7171
WXAssertComponentThread();
72-
73-
if (flexIsUndefined(self.flexCssNode->getStyleWidth())) {
74-
self.flexCssNode->setStyleWidth(((WXScrollerComponent *)(self.supercomponent)).flexScrollerCSSNode->getStyleWidth(),NO);
75-
}
76-
77-
if ([self needsLayout]) {
78-
std::pair<float, float> renderPageSize;
79-
renderPageSize.first = self.weexInstance.frame.size.width;
80-
renderPageSize.second = self.weexInstance.frame.size.height;
81-
self.flexCssNode->calculateLayout(renderPageSize);
82-
if ([WXLog logLevel] >= WXLogLevelDebug) {
83-
84-
}
85-
}
72+
if (flexIsUndefined(self.flexCssNode->getStyleWidth())) {
73+
self.flexCssNode->setStyleWidth(((WXScrollerComponent *)(self.supercomponent)).flexScrollerCSSNode->getStyleWidth(),NO);
74+
}
8675

76+
if ([self needsLayout]) {
77+
std::pair<float, float> renderPageSize;
78+
renderPageSize.first = self.weexInstance.frame.size.width;
79+
renderPageSize.second = self.weexInstance.frame.size.height;
80+
self.flexCssNode->calculateLayout(renderPageSize);
81+
}
8782
NSMutableSet<WXComponent *> *dirtyComponents = [NSMutableSet set];
8883
[self _calculateFrameWithSuperAbsolutePosition:CGPointZero gatherDirtyComponents:dirtyComponents];
8984
for (WXComponent *dirtyComponent in dirtyComponents) {
@@ -92,5 +87,4 @@ - (void)triggerLayout
9287
}];
9388
}
9489
}
95-
9690
@end

ios/sdk/WeexSDK/Sources/Component/RecycleList/WXComponent+DataBinding.mm

Lines changed: 103 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -89,44 +89,46 @@ - (void)updateBindingData:(NSDictionary *)data
8989
return;
9090
}
9191

92-
if (templateComponent->_bindingProps) {
93-
__block NSMutableDictionary *newData = [NSMutableDictionary dictionary];
94-
[templateComponent->_bindingProps enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, WXDataBindingBlock _Nonnull block, BOOL * _Nonnull stop) {
95-
BOOL needUpdate;
96-
id value = block(data, &needUpdate);
97-
if (value) {
98-
newData[key] = value;
99-
}
100-
}];
101-
102-
if (self.attributes[@"@isComponentRoot"]) {
103-
if (![recycleListComponent.dataManager virtualComponentDataWithIndexPath:indexPath]) {
104-
static NSUInteger __componentId = 0;
105-
self->_virtualComponentId = [NSString stringWithFormat:@"%@%lu", listRef, (unsigned long)__componentId % (2048*1024)];
106-
__componentId++;
107-
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
108-
[[WXSDKManager bridgeMgr] callComponentHook:self.weexInstance.instanceId componentId:self.attributes[@"@templateId"] type:@"lifecycle" hook:@"create" args:@[self->_virtualComponentId, newData] competion:^(JSValue *value) {
109-
[newData addEntriesFromDictionary:[value toDictionary][@"0"]];
110-
[newData setObject:indexPath forKey:@"indexPath"];
111-
[newData setObject:listRef forKey:@"recycleListComponentRef"];
112-
[[recycleListComponent dataManager] updateVirtualComponentData:self->_virtualComponentId data:newData];
113-
dispatch_semaphore_signal(semaphore);
114-
}];
115-
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
116-
117-
[[WXSDKManager bridgeMgr] callComponentHook:self.weexInstance.instanceId componentId:self->_virtualComponentId type:@"lifecycle" hook:@"attach" args:nil competion:nil];
118-
if ([newData count]) {
119-
data = newData;
120-
}
121-
} else {
122-
newData[@"componentDataId"] = self->_virtualComponentId;
123-
NSDictionary * virtualComponentData = [recycleListComponent.dataManager virtualComponentDataWithIndexPath:indexPath];
124-
[newData addEntriesFromDictionary:virtualComponentData];
125-
[newData addEntriesFromDictionary:data];
92+
__block NSMutableDictionary *newData = [NSMutableDictionary dictionary];
93+
[templateComponent->_bindingProps enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, WXDataBindingBlock _Nonnull block, BOOL * _Nonnull stop) {
94+
BOOL needUpdate;
95+
id value = block(data, &needUpdate);
96+
if (value) {
97+
newData[key] = value;
98+
}
99+
}];
100+
101+
if (self.attributes[@"@isComponentRoot"]) {
102+
if (![recycleListComponent.dataManager virtualComponentDataWithIndexPath:indexPath]) {
103+
static NSUInteger __componentId = 0;
104+
self->_virtualComponentId = [NSString stringWithFormat:@"%@@%lu", listRef, (unsigned long)__componentId % (2048*1024)];
105+
__componentId++;
106+
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
107+
[[WXSDKManager bridgeMgr] callComponentHook:self.weexInstance.instanceId componentId:self.attributes[@"@templateId"] type:@"lifecycle" hook:@"create" args:@[self->_virtualComponentId, newData] competion:^(JSValue *value) {
108+
[newData addEntriesFromDictionary:[value toDictionary][@"0"]];
109+
[newData setObject:indexPath forKey:@"indexPath"];
110+
[newData setObject:listRef forKey:@"recycleListComponentRef"];
111+
[[recycleListComponent dataManager] updateVirtualComponentData:self->_virtualComponentId data:newData];
112+
dispatch_semaphore_signal(semaphore);
113+
}];
114+
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
115+
116+
[self _refsConventFromData:newData];
117+
NSIndexPath *indexPath = newData[@"item"][@"indexPath"];
118+
NSUInteger position = [indexPath indexAtPosition:1];
119+
[[WXSDKManager bridgeMgr] callComponentHook:self.weexInstance.instanceId componentId:self->_virtualComponentId type:@"lifecycle" hook:@"attach" args:@[@{@"virtualComponentId":self->_virtualComponentId,@"position":@(position),@"refs":self->_virtalElementInfo[@"refs"]?:@{}}] competion:nil];
120+
if ([newData count]) {
126121
data = newData;
127122
}
123+
} else {
124+
newData[@"componentDataId"] = self->_virtualComponentId;
125+
NSDictionary * virtualComponentData = [recycleListComponent.dataManager virtualComponentDataWithIndexPath:indexPath];
126+
[newData addEntriesFromDictionary:virtualComponentData];
127+
[newData addEntriesFromDictionary:data];
128+
data = newData;
128129
}
129130
}
131+
130132
if (phase) {
131133
NSMutableDictionary * newData = [data mutableCopy];
132134
newData[@"@phase"] = phase;
@@ -532,4 +534,71 @@ - (WXDataBindingBlock)bindingBlockWithExpression:(WXJSExpression *)expression
532534
return block;
533535
}
534536

537+
- (void)_attachSlotEvent:(NSDictionary *)data
538+
{
539+
[self _refsConventFromData:data];
540+
if (_virtalElementInfo.count != 0) {
541+
NSIndexPath *indexPath = data[@"item"][@"indexPath"];
542+
NSUInteger position = [indexPath indexAtPosition:1];
543+
[_virtalElementInfo addEntriesFromDictionary:@{@"position":@(position)}];
544+
[[WXSDKManager bridgeMgr] fireEvent:self.weexInstance.instanceId ref:data[@"item"][@"recycleListComponentRef"] type:@"_attach_slot" params:_virtalElementInfo domChanges:nil handlerArguments:nil];
545+
}
546+
}
547+
548+
- (void)_detachSlotEvent:(NSDictionary *)data
549+
{
550+
[self _refsConventFromData:data];
551+
if (_virtalElementInfo.count != 0) {
552+
NSIndexPath *indexPath = data[@"item"][@"indexPath"];
553+
NSUInteger position = [indexPath indexAtPosition:1];
554+
[_virtalElementInfo addEntriesFromDictionary:@{@"position":@(position)}];
555+
[[WXSDKManager bridgeMgr] fireEvent:self.weexInstance.instanceId ref:data[@"item"][@"recycleListComponentRef"] type:@"_detach_slot" params:_virtalElementInfo domChanges:nil handlerArguments:nil];
556+
}
557+
}
558+
559+
- (void )_refsConventFromData:(NSDictionary *)data
560+
{
561+
_virtalElementInfo = [NSMutableDictionary new];
562+
if (self.attributes[@"ref"]) {
563+
NSMutableDictionary *subInfo = [NSMutableDictionary new];
564+
[self _componentInfoOfRef:self subInfo:subInfo data:data];
565+
[self _recursiveSlotComponent:self subInfo:subInfo data:data];
566+
}
567+
else
568+
{
569+
[self _recursiveSlotComponent:self subInfo:nil data:data];
570+
}
571+
}
572+
573+
- (void)_recursiveSlotComponent:(WXComponent *)component subInfo:(NSMutableDictionary *)subInfo data:(NSDictionary *)data
574+
{
575+
subInfo = subInfo ? : [NSMutableDictionary new];
576+
for (WXComponent *subcomponent in component.subcomponents) {
577+
if (subcomponent.subcomponents.count != 0) {
578+
[self _recursiveSlotComponent:subcomponent subInfo:subInfo data:data];
579+
}
580+
[self _componentInfoOfRef:subcomponent subInfo:subInfo data:data];
581+
}
582+
if (subInfo.count !=0) {
583+
[_virtalElementInfo setObject:subInfo forKey:@"refs"];
584+
}
585+
}
586+
587+
- (void)_componentInfoOfRef:(WXComponent *)component subInfo:(NSMutableDictionary *)subInfo data:(NSDictionary *)data
588+
{
589+
if (component.attributes[@"ref"]) {
590+
NSIndexPath *indexPath = data[@"item"][@"indexPath"];
591+
NSUInteger position = [indexPath indexAtPosition:1];
592+
NSString *virtalElementInfo = [NSString stringWithFormat:@"%@@%lu",component.ref,position];
593+
NSDictionary *refInfo = @{@"attrs":component.attributes,@"type":component->_type,@"ref":virtalElementInfo,@"[[VirtualElement]]":@"true"};
594+
if (subInfo[component.attributes[@"ref"]]) {
595+
[subInfo[component.attributes[@"ref"]] addObject:refInfo];
596+
}
597+
else
598+
{
599+
[subInfo setValue:@[refInfo] forKey:component.attributes[@"ref"]];
600+
}
601+
}
602+
}
603+
535604
@end

ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListComponent.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,4 @@
2929
@property(nonatomic, strong) WXRecycleListDataManager *dataManager;
3030
@property(nonatomic, strong) WXRecycleListTemplateManager *templateManager;
3131
@property(nonatomic, strong) WXRecycleListUpdateManager *updateManager;
32-
33-
3432
@end

0 commit comments

Comments
 (0)