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

Commit 89c8a13

Browse files
authored
Migrate iOS and Android to use pushRouteInformation (#39372)
* Migrate iOS and Android to use pushRouteInformation * revert * fix test
1 parent 0d56533 commit 89c8a13

File tree

5 files changed

+41
-23
lines changed

5 files changed

+41
-23
lines changed

shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -829,11 +829,13 @@ void onRequestPermissionsResult(
829829
void onNewIntent(@NonNull Intent intent) {
830830
ensureAlive();
831831
if (flutterEngine != null) {
832-
Log.v(TAG, "Forwarding onNewIntent() to FlutterEngine and sending pushRoute message.");
832+
Log.v(
833+
TAG,
834+
"Forwarding onNewIntent() to FlutterEngine and sending pushRouteInformation message.");
833835
flutterEngine.getActivityControlSurface().onNewIntent(intent);
834836
String initialRoute = maybeGetInitialRouteFromIntent(intent);
835837
if (initialRoute != null && !initialRoute.isEmpty()) {
836-
flutterEngine.getNavigationChannel().pushRoute(initialRoute);
838+
flutterEngine.getNavigationChannel().pushRouteInformation(initialRoute);
837839
}
838840
} else {
839841
Log.w(TAG, "onNewIntent() invoked before FlutterFragment was attached to an Activity.");

shell/platform/android/io/flutter/embedding/engine/systemchannels/NavigationChannel.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import io.flutter.plugin.common.JSONMethodCodec;
1212
import io.flutter.plugin.common.MethodCall;
1313
import io.flutter.plugin.common.MethodChannel;
14+
import java.util.HashMap;
15+
import java.util.Map;
1416

1517
/** TODO(mattcarroll): fill in javadoc for NavigationChannel. */
1618
public class NavigationChannel {
@@ -43,6 +45,13 @@ public void pushRoute(@NonNull String route) {
4345
channel.invokeMethod("pushRoute", route);
4446
}
4547

48+
public void pushRouteInformation(@NonNull String route) {
49+
Log.v(TAG, "Sending message to push route information '" + route + "'");
50+
Map<String, String> message = new HashMap<>();
51+
message.put("location", route);
52+
channel.invokeMethod("pushRouteInformation", message);
53+
}
54+
4655
public void popRoute() {
4756
Log.v(TAG, "Sending message to pop route.");
4857
channel.invokeMethod("popRoute", null);

shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ public void itSendsdefaultInitialRouteOnStartIfNotDeepLinkingFromIntent() {
726726
}
727727

728728
@Test
729-
public void itSendsPushRouteMessageWhenOnNewIntent() {
729+
public void itSendsPushRouteInformationMessageWhenOnNewIntent() {
730730
when(mockHost.shouldHandleDeeplinking()).thenReturn(true);
731731
// Create the real object that we're testing.
732732
FlutterActivityAndFragmentDelegate delegate = new FlutterActivityAndFragmentDelegate(mockHost);
@@ -742,11 +742,11 @@ public void itSendsPushRouteMessageWhenOnNewIntent() {
742742

743743
// Verify that the navigation channel was given the push route message.
744744
verify(mockFlutterEngine.getNavigationChannel(), times(1))
745-
.pushRoute("/custom/route?query=test");
745+
.pushRouteInformation("/custom/route?query=test");
746746
}
747747

748748
@Test
749-
public void itDoesNotSendPushRouteMessageWhenOnNewIntentIsNonHierarchicalUri() {
749+
public void itDoesNotSendPushRouteInformationMessageWhenOnNewIntentIsNonHierarchicalUri() {
750750
when(mockHost.shouldHandleDeeplinking()).thenReturn(true);
751751
// Create the real object that we're testing.
752752
FlutterActivityAndFragmentDelegate delegate = new FlutterActivityAndFragmentDelegate(mockHost);
@@ -764,11 +764,12 @@ public void itDoesNotSendPushRouteMessageWhenOnNewIntentIsNonHierarchicalUri() {
764764
delegate.onNewIntent(mockIntent);
765765

766766
// Verify that the navigation channel was not given a push route message.
767-
verify(mockFlutterEngine.getNavigationChannel(), times(0)).pushRoute("mailto:[email protected]");
767+
verify(mockFlutterEngine.getNavigationChannel(), times(0))
768+
.pushRouteInformation("mailto:[email protected]");
768769
}
769770

770771
@Test
771-
public void itSendsPushRouteMessageWhenOnNewIntentWithQueryParameterAndFragment() {
772+
public void itSendsPushRouteInformationMessageWhenOnNewIntentWithQueryParameterAndFragment() {
772773
when(mockHost.shouldHandleDeeplinking()).thenReturn(true);
773774
// Create the real object that we're testing.
774775
FlutterActivityAndFragmentDelegate delegate = new FlutterActivityAndFragmentDelegate(mockHost);
@@ -785,11 +786,11 @@ public void itSendsPushRouteMessageWhenOnNewIntentWithQueryParameterAndFragment(
785786

786787
// Verify that the navigation channel was given the push route message.
787788
verify(mockFlutterEngine.getNavigationChannel(), times(1))
788-
.pushRoute("/custom/route?query=test#fragment");
789+
.pushRouteInformation("/custom/route?query=test#fragment");
789790
}
790791

791792
@Test
792-
public void itSendsPushRouteMessageWhenOnNewIntentWithFragmentNoQueryParameter() {
793+
public void itSendsPushRouteInformationMessageWhenOnNewIntentWithFragmentNoQueryParameter() {
793794
when(mockHost.shouldHandleDeeplinking()).thenReturn(true);
794795
// Create the real object that we're testing.
795796
FlutterActivityAndFragmentDelegate delegate = new FlutterActivityAndFragmentDelegate(mockHost);
@@ -804,11 +805,12 @@ public void itSendsPushRouteMessageWhenOnNewIntentWithFragmentNoQueryParameter()
804805
delegate.onNewIntent(mockIntent);
805806

806807
// Verify that the navigation channel was given the push route message.
807-
verify(mockFlutterEngine.getNavigationChannel(), times(1)).pushRoute("/custom/route#fragment");
808+
verify(mockFlutterEngine.getNavigationChannel(), times(1))
809+
.pushRouteInformation("/custom/route#fragment");
808810
}
809811

810812
@Test
811-
public void itSendsPushRouteMessageWhenOnNewIntentNoQueryParameter() {
813+
public void itSendsPushRouteInformationMessageWhenOnNewIntentNoQueryParameter() {
812814
when(mockHost.shouldHandleDeeplinking()).thenReturn(true);
813815
// Create the real object that we're testing.
814816
FlutterActivityAndFragmentDelegate delegate = new FlutterActivityAndFragmentDelegate(mockHost);
@@ -823,7 +825,8 @@ public void itSendsPushRouteMessageWhenOnNewIntentNoQueryParameter() {
823825
delegate.onNewIntent(mockIntent);
824826

825827
// Verify that the navigation channel was given the push route message.
826-
verify(mockFlutterEngine.getNavigationChannel(), times(1)).pushRoute("/custom/route");
828+
verify(mockFlutterEngine.getNavigationChannel(), times(1))
829+
.pushRouteInformation("/custom/route");
827830
}
828831

829832
@Test

shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,11 @@ - (BOOL)openURL:(NSURL*)url {
157157
if ([url.fragment length] != 0) {
158158
fullRoute = [NSString stringWithFormat:@"%@#%@", fullRoute, url.fragment];
159159
}
160-
[flutterViewController.engine.navigationChannel invokeMethod:@"pushRoute"
161-
arguments:fullRoute];
160+
[flutterViewController.engine.navigationChannel
161+
invokeMethod:@"pushRouteInformation"
162+
arguments:@{
163+
@"location" : fullRoute,
164+
}];
162165
}
163166
}];
164167
return YES;

shell/platform/darwin/ios/framework/Source/FlutterAppDelegateTest.mm

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ - (void)testLaunchUrl {
6767
openURL:[NSURL URLWithString:@"http://myApp/custom/route?query=test"]
6868
options:@{}];
6969
XCTAssertTrue(result);
70-
OCMVerify([self.mockNavigationChannel invokeMethod:@"pushRoute"
71-
arguments:@"/custom/route?query=test"]);
70+
OCMVerify([self.mockNavigationChannel invokeMethod:@"pushRouteInformation"
71+
arguments:@{@"location" : @"/custom/route?query=test"}]);
7272
}
7373

7474
- (void)testLaunchUrlWithDeepLinkingNotSet {
@@ -104,8 +104,9 @@ - (void)testLaunchUrlWithQueryParameterAndFragment {
104104
openURL:[NSURL URLWithString:@"http://myApp/custom/route?query=test#fragment"]
105105
options:@{}];
106106
XCTAssertTrue(result);
107-
OCMVerify([self.mockNavigationChannel invokeMethod:@"pushRoute"
108-
arguments:@"/custom/route?query=test#fragment"]);
107+
OCMVerify([self.mockNavigationChannel
108+
invokeMethod:@"pushRouteInformation"
109+
arguments:@{@"location" : @"/custom/route?query=test#fragment"}]);
109110
}
110111

111112
- (void)testLaunchUrlWithFragmentNoQueryParameter {
@@ -117,8 +118,8 @@ - (void)testLaunchUrlWithFragmentNoQueryParameter {
117118
openURL:[NSURL URLWithString:@"http://myApp/custom/route#fragment"]
118119
options:@{}];
119120
XCTAssertTrue(result);
120-
OCMVerify([self.mockNavigationChannel invokeMethod:@"pushRoute"
121-
arguments:@"/custom/route#fragment"]);
121+
OCMVerify([self.mockNavigationChannel invokeMethod:@"pushRouteInformation"
122+
arguments:@{@"location" : @"/custom/route#fragment"}]);
122123
}
123124

124125
- (void)testReleasesWindowOnDealloc {
@@ -139,7 +140,7 @@ - (void)testReleasesWindowOnDealloc {
139140

140141
#pragma mark - Deep linking
141142

142-
- (void)testUniversalLinkPushRoute {
143+
- (void)testUniversalLinkPushRouteInformation {
143144
OCMStub([self.mockMainBundle objectForInfoDictionaryKey:@"FlutterDeepLinkingEnabled"])
144145
.andReturn(@YES);
145146

@@ -151,8 +152,8 @@ - (void)testUniversalLinkPushRoute {
151152
restorationHandler:^(NSArray<id<UIUserActivityRestoring>>* __nullable restorableObjects){
152153
}];
153154
XCTAssertTrue(result);
154-
OCMVerify([self.mockNavigationChannel invokeMethod:@"pushRoute"
155-
arguments:@"/custom/route?query=test"]);
155+
OCMVerify([self.mockNavigationChannel invokeMethod:@"pushRouteInformation"
156+
arguments:@{@"location" : @"/custom/route?query=test"}]);
156157
}
157158

158159
@end

0 commit comments

Comments
 (0)