Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,18 @@ - (NSData*)encode:(id)message {
return nil;
}
NSData* encoding;
NSError* error;
if ([message isKindOfClass:[NSArray class]] || [message isKindOfClass:[NSDictionary class]]) {
encoding = [NSJSONSerialization dataWithJSONObject:message options:0 error:nil];
encoding = [NSJSONSerialization dataWithJSONObject:message options:0 error:&error];
} else {
// NSJSONSerialization does not support top-level simple values.
// We encode as singleton array, then extract the relevant bytes.
encoding = [NSJSONSerialization dataWithJSONObject:@[ message ] options:0 error:nil];
encoding = [NSJSONSerialization dataWithJSONObject:@[ message ] options:0 error:&error];
if (encoding) {
encoding = [encoding subdataWithRange:NSMakeRange(1, encoding.length - 2)];
}
}
NSAssert(encoding, @"Invalid JSON message, encoding failed");
NSAssert(encoding, @"Invalid JSON message, encoding failed: %@", error);
return encoding;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ - (void)forwardInvocation:(NSInvocation*)anInvocation {
@interface FlutterTextInputPlugin ()
@property(nonatomic, readonly) fml::WeakPtr<FlutterTextInputPlugin> weakPtr;
@property(nonatomic, readonly) id<FlutterTextInputDelegate> textInputDelegate;
@property(nonatomic, readonly) UIView* hostView;
@end

@interface FlutterTextInputView ()
Expand Down Expand Up @@ -1602,7 +1603,10 @@ - (CGRect)firstRectForRange:(UITextRange*)range {
_cachedFirstRect = [self localRectFromFrameworkTransform:rect];
}

return _cachedFirstRect;
UIView* hostView = _textInputPlugin.get().hostView;
NSAssert(hostView == nil || [self isDescendantOfView:hostView], @"%@ is not a descendant of %@",
self, hostView);
return hostView ? [hostView convertRect:_cachedFirstRect toView:self] : _cachedFirstRect;
}

if (_scribbleInteractionStatus == FlutterScribbleInteractionStatusNone &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,11 @@ - (void)testInputViewsDoNotHaveUITextInteractions {
#pragma mark - UITextInput methods - Tests

- (void)testUpdateFirstRectForRange {
FlutterTextInputView* inputView = [[FlutterTextInputView alloc] initWithOwner:textInputPlugin];
[self setClientId:123 configuration:self.mutableTemplateCopy];

FlutterTextInputView* inputView = textInputPlugin.activeView;
textInputPlugin.viewController.view.frame = CGRectMake(0, 0, 0, 0);

[inputView
setTextInputState:@{@"text" : @"COMPOSING", @"composingBase" : @1, @"composingExtent" : @3}];

Expand Down Expand Up @@ -1272,6 +1276,16 @@ - (void)testUpdateFirstRectForRange {
[inputView setMarkedRect:testRect];
XCTAssertTrue(
CGRectEqualToRect(CGRectMake(-306, 3, 300, 300), [inputView firstRectForRange:range]));

NSAssert(inputView.superview, @"inputView is not in the view hierarchy!");
const CGPoint offset = CGPointMake(113, 119);
CGRect currentFrame = inputView.frame;
currentFrame.origin = offset;
inputView.frame = currentFrame;
// Moving the input view within the FlutterView shouldn't affect the coordinates,
// since the framework sends us global coordinates.
XCTAssertTrue(CGRectEqualToRect(CGRectMake(-306 - 113, 3 - 119, 300, 300),
[inputView firstRectForRange:range]));
}

- (void)testFirstRectForRangeReturnsCorrectSelectionRect {
Expand Down