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

Conversation

@Jasguerrero
Copy link
Contributor

@Jasguerrero Jasguerrero commented Feb 18, 2022

Issue: flutter/flutter#4703

Framework PR: flutter/flutter#99078

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides].
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See [testing the engine] for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the [CLA].
  • All existing and new tests are passing.

@Jasguerrero Jasguerrero marked this pull request as ready for review February 24, 2022 19:02
@Jasguerrero Jasguerrero requested a review from jmagman February 24, 2022 19:02
Copy link
Member

@jmagman jmagman left a comment

Choose a reason for hiding this comment

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

Also add a test for the FlutterEngine logic change. This test passed on your PR, you can put it right after

- (void)testRunningInitialRouteSendsNavigationMessage {

- (void)testInitialRouteSettingsSendsNavigationMessage {
  id mockBinaryMessenger = OCMClassMock([FlutterBinaryMessengerRelay class]);

  auto settings = FLTDefaultSettingsForBundle();
  settings.route = "test";
  FlutterDartProject* project = [[FlutterDartProject alloc] initWithSettings:settings];
  FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"foobar" project:project];
  [engine setBinaryMessenger:mockBinaryMessenger];
  [engine run];

  // Now check that an encoded method call has been made on the binary messenger to set the
  // initial route to "test".
  FlutterMethodCall* setInitialRouteMethodCall =
      [FlutterMethodCall methodCallWithMethodName:@"setInitialRoute" arguments:@"test"];
  NSData* encodedSetInitialRouteMethod =
      [[FlutterJSONMethodCodec sharedInstance] encodeMethodCall:setInitialRouteMethodCall];
  OCMVerify([mockBinaryMessenger sendOnChannel:@"flutter/navigation"
                                       message:encodedSetInitialRouteMethod]);
}

Comment on lines 695 to 701
self.initialRoute = initialRoute;

auto settings = [_dartProject.get() settings];
if (settings.route.empty() == false) {
self.initialRoute = [NSString stringWithCString:settings.route.c_str()
encoding:[NSString defaultCStringEncoding]];
}
Copy link
Member

Choose a reason for hiding this comment

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

I think defaultCStringEncoding usage is discouraged, let's just accept utf8 here.
Also, don't set the initialRoute twice.

Suggested change
self.initialRoute = initialRoute;
auto settings = [_dartProject.get() settings];
if (settings.route.empty() == false) {
self.initialRoute = [NSString stringWithCString:settings.route.c_str()
encoding:[NSString defaultCStringEncoding]];
}
auto settings = [_dartProject.get() settings];
if (initialRoute != nil) {
self.initialRoute = initialRoute;
} else if (settings.route.empty() == false) {
self.initialRoute = [NSString stringWithCString:settings.route.c_str()
encoding:NSUTF8StringEncoding];
}

@Jasguerrero Jasguerrero requested a review from jmagman March 2, 2022 19:17
Copy link
Member

@jmagman jmagman left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for tracking this down I know it was trickier than it looks!

@Jasguerrero Jasguerrero added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Mar 2, 2022
@Jasguerrero
Copy link
Contributor Author

LGTM, thanks for tracking this down I know it was trickier than it looks!

Thank you for all your help!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

platform-ios waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants