Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
finish nsobject
  • Loading branch information
bparrishMines committed Jun 8, 2022
commit b83c2cc90320b758e9807fd9762488a3df3f0632
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,13 @@ extern WKNavigationActionPolicy FWFWKNavigationActionPolicyFromEnumData(FWFWKNav
*/
extern FWFNSErrorData *FWFNSErrorDataFromNSError(NSError *error);

/**
* Converts an NSKeyValueChangeKey to a FWFNSKeyValueChangeKeyEnumData.
*
* @param key The data object containing information to create a FWFNSKeyValueChangeKeyEnumData.
*
* @return A FWFNSKeyValueChangeKeyEnumData or nil if data could not be converted.
*/
extern FWFNSKeyValueChangeKeyEnumData *FWFNSKeyValueChangeKeyEnumDataFromNSKeyValueChangeKey(NSKeyValueChangeKey key);

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,23 @@ WKNavigationActionPolicy FWFWKNavigationActionPolicyFromEnumData(FWFWKNavigation
FWFNSErrorData *FWFNSErrorDataFromNSError(NSError *error) {
return [FWFNSErrorData makeWithCode:@(error.code) domain:error.domain localiziedDescription:error.localizedDescription];
}

FWFNSKeyValueChangeKeyEnumData *FWFNSKeyValueChangeKeyEnumDataFromNSKeyValueChangeKey(NSKeyValueChangeKey key) {
if ([key isEqualToString:NSKeyValueChangeIndexesKey]) {
return [FWFNSKeyValueChangeKeyEnumData makeWithValue:FWFNSKeyValueChangeKeyEnumIndexes];
} else
if ([key isEqualToString:NSKeyValueChangeKindKey]) {
return [FWFNSKeyValueChangeKeyEnumData makeWithValue:FWFNSKeyValueChangeKeyEnumKind];
}else
if ([key isEqualToString:NSKeyValueChangeNewKey]) {
return [FWFNSKeyValueChangeKeyEnumData makeWithValue:FWFNSKeyValueChangeKeyEnumNewValue];
}else
if ([key isEqualToString:NSKeyValueChangeNotificationIsPriorKey]) {
return [FWFNSKeyValueChangeKeyEnumData makeWithValue:FWFNSKeyValueChangeKeyEnumNotificationIsPrior];
}else
if ([key isEqualToString:NSKeyValueChangeOldKey]) {
return [FWFNSKeyValueChangeKeyEnumData makeWithValue:FWFNSKeyValueChangeKeyEnumOldValue];
}

return nil;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,31 @@ - (instancetype)initWithBinaryMessenger:(id<FlutterBinaryMessenger>)binaryMessen
}
return self;
}

- (long)identifierForObject:(NSObject *)instance {
return [self.instanceManager identifierWithStrongReferenceForInstance:instance];
}

- (void)observeValueForObject:(NSObject *)instance
keyPath:(NSString *)keyPath
object:(NSObject *)object
change:(NSDictionary<NSKeyValueChangeKey, id> *)change
completion:(void (^)(NSError * _Nullable))completion {
NSMutableArray<FWFNSKeyValueChangeKeyEnumData *> *changeKeys = [NSMutableArray array];
NSMutableArray<id> *changeValues = [NSMutableArray array];

[change enumerateKeysAndObjectsUsingBlock:^(NSKeyValueChangeKey key, id value, BOOL* stop) {
[changeKeys addObject:FWFNSKeyValueChangeKeyEnumDataFromNSKeyValueChangeKey(key)];
[changeValues addObject:value];
}];

[self observeValueForObjectWithIdentifier:@([self identifierForObject:instance])
keyPath:keyPath
objectIdentifier:@([self.instanceManager identifierWithStrongReferenceForInstance:object])
changeKeys:changeKeys
changeValues:changeValues
completion:completion];
}
@end

@implementation FWFObject
Expand All @@ -31,6 +56,12 @@ - (instancetype)initWithBinaryMessenger:(id<FlutterBinaryMessenger>)binaryMessen
}
return self;
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
[self.objectApi observeValueForObject:self keyPath:keyPath object:object change:change completion:^(NSError *error) {
NSAssert(!error, @"%@", error);
}];
}
@end

@interface FWFObjectHostApiImpl ()
Expand Down