-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent creation of button react view with the same componentId (#5687)
When updating buttons with mergeOptions, existing custom buttons are unmounted and then recreated. This commit adds an optimisation which prevents the react components from being recreated. To avoid unnecessary recreation, add an `id` to the component. If an existing react view is found for that id, it will be reused.
- Loading branch information
Showing
7 changed files
with
214 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#import <Foundation/Foundation.h> | ||
|
||
@interface NSArray (utils) | ||
|
||
- (NSArray *)intersect:(NSArray *)array withPropertyName:(NSString *)propertyName; | ||
|
||
- (NSArray *)difference:(NSArray *)array withPropertyName:(NSString *)propertyName; | ||
|
||
- (NSArray *)mapObjectsUsingBlock:(id (^)(id obj, NSUInteger idx))block; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#import "NSArray+utils.h" | ||
|
||
@implementation NSArray (utils) | ||
|
||
- (NSArray *)intersect:(NSArray *)array withPropertyName:(NSString *)propertyName { | ||
NSMutableArray* intersection = [NSMutableArray new]; | ||
for (NSObject* object in array) { | ||
NSArray* filteredArray = [self filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"%@ == %@", propertyName, object]]; | ||
[intersection addObjectsFromArray:filteredArray]; | ||
} | ||
|
||
return [NSArray arrayWithArray:intersection]; | ||
} | ||
|
||
- (NSArray *)difference:(NSArray *)array withPropertyName:(NSString *)propertyName { | ||
NSMutableArray* diff = [NSMutableArray arrayWithArray:self]; | ||
NSArray* intersection = [self intersect:array withPropertyName:propertyName]; | ||
[diff removeObjectsInArray:intersection]; | ||
|
||
return [NSArray arrayWithArray:diff]; | ||
} | ||
|
||
- (NSArray *)mapObjectsUsingBlock:(id (^)(id obj, NSUInteger idx))block { | ||
NSMutableArray *result = [NSMutableArray arrayWithCapacity:[self count]]; | ||
[self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { | ||
[result addObject:block(obj, idx)]; | ||
}]; | ||
return result; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.