Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[ios] Convert int in Dart to long long in Objective-C #39331

Merged
merged 1 commit into from
Feb 9, 2023
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 @@ -193,14 +193,14 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,
void FlutterPlatformViewsController::OnCreate(FlutterMethodCall* call, FlutterResult& result) {
NSDictionary<NSString*, id>* args = [call arguments];

long viewId = [args[@"id"] longValue];
int64_t viewId = [args[@"id"] longLongValue];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to use long long instead?

Suggested change
int64_t viewId = [args[@"id"] longLongValue];
long long viewId = [args[@"id"] longLongValue];

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using int64_t was recommended in the google c++ style guide for the below reason:
https://google.github.io/styleguide/cppguide.html#Integer_Types

The standard library header <cstdint> defines types like int16_t, uint32_t, int64_t, etc. You should always use those in preference to short, unsigned long long and the like, when you need a guarantee on the size of an integer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That style guide makes sense, but I think it's saying that the value coming out of args[@"id"] should be enforced to be a int64_t since that's what it's set to on the dart side. But at the point -longLongValue is being used it's a long long. This is all pedantic though since int64_t is typedef'd to long long on macOS, watchOS, tvOS, and iOS.

NSString* viewTypeString = args[@"viewType"];
std::string viewType(viewTypeString.UTF8String);

if (views_.count(viewId) != 0) {
result([FlutterError errorWithCode:@"recreating_view"
message:@"trying to create an already created view"
details:[NSString stringWithFormat:@"view id: '%ld'", viewId]]);
details:[NSString stringWithFormat:@"view id: '%lld'", viewId]]);
}

NSObject<FlutterPlatformViewFactory>* factory = factories_[viewType].get();
Expand Down Expand Up @@ -234,7 +234,8 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,
arguments:params];
UIView* platform_view = [embedded_view view];
// Set a unique view identifier, so the platform view can be identified in unit tests.
platform_view.accessibilityIdentifier = [NSString stringWithFormat:@"platform_view[%ld]", viewId];
platform_view.accessibilityIdentifier =
[NSString stringWithFormat:@"platform_view[%lld]", viewId];
views_[viewId] = fml::scoped_nsobject<NSObject<FlutterPlatformView>>([embedded_view retain]);

FlutterTouchInterceptingView* touch_interceptor = [[[FlutterTouchInterceptingView alloc]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ - (void)handleMethodCall:(nonnull FlutterMethodCall*)call result:(nonnull Flutte
if ([[call method] isEqualToString:@"create"]) {
NSMutableDictionary<NSString*, id>* args = [call arguments];
if ([args objectForKey:@"id"]) {
int64_t viewId = [args[@"id"] longValue];
int64_t viewId = [args[@"id"] longLongValue];
NSString* viewType = [NSString stringWithUTF8String:([args[@"viewType"] UTF8String])];
[self onCreateWithViewID:viewId viewType:viewType result:result];
} else {
Expand All @@ -100,7 +100,7 @@ - (void)handleMethodCall:(nonnull FlutterMethodCall*)call result:(nonnull Flutte
}
} else if ([[call method] isEqualToString:@"dispose"]) {
NSNumber* arg = [call arguments];
int64_t viewId = [arg longValue];
int64_t viewId = [arg longLongValue];
[self onDisposeWithViewID:viewId result:result];
} else {
result(FlutterMethodNotImplemented);
Expand Down