@@ -89,44 +89,46 @@ - (void)updateBindingData:(NSDictionary *)data
89
89
return ;
90
90
}
91
91
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 ]) {
126
121
data = newData;
127
122
}
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;
128
129
}
129
130
}
131
+
130
132
if (phase) {
131
133
NSMutableDictionary * newData = [data mutableCopy ];
132
134
newData[@" @phase" ] = phase;
@@ -532,4 +534,71 @@ - (WXDataBindingBlock)bindingBlockWithExpression:(WXJSExpression *)expression
532
534
return block;
533
535
}
534
536
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
+
535
604
@end
0 commit comments