Repository navigation
Conversation
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. |
… report unheard display messages firebase-inappmessaging-display removes all listeners on every activity pause, so the lifecycle streams went silent on Android after the app was backgrounded or a campaign opened another activity. The listeners are now added again when an activity resumes. A campaign sent to onMessageDisplay while nothing listened was dropped and never reported, which on iOS blocks every later campaign. It is now held for the first listener and reported as a display error if none subscribes within 5 seconds.
A message that arrives on `onMessageDisplay` while nothing listens is still held for the first listener for a few seconds. When none arrives: - iOS reports it as a display error, as before, so the SDK releases its display lock and can show the next campaign. `onMessageDisplayError` fires for it. - Android now only drops it. `displayErrorEncountered` stores a campaign impression there, and for app open campaigns uses up the one a day app open limit, for a message nobody saw. Android has no display lock, so the campaign stays eligible and triggers again. On Android, disabling custom display while it is already off, which `onDetachedFromEngine` also does, no longer pauses and resumes the default display on the current activity. That restarted a default message on screen and dropped the listeners of other engines. The plugin's SDK calls now go through an internal seam, so JUnit tests drive its activity lifecycle wiring against a fake `Application`.
6a21b26 to
6aeb37b
Compare
|
Since this PR already touches The documented snippet: await message.click(message.primaryAction ?? message.action!);
await message.dismiss();1. 2. Reproduction — pure Dart, no Firebase project, native SDK or device needed
name: iam_repro
publish_to: none
environment:
sdk: ^3.6.0
dependencies:
firebase_in_app_messaging_platform_interface: ^0.2.7
flutter:
sdk: flutter
dev_dependencies:
flutter_test:
sdk: flutter
import 'package:firebase_in_app_messaging_platform_interface/firebase_in_app_messaging_platform_interface.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
late List<String> reported;
setUp(() => reported = <String>[]);
InAppMessage buildMessage({
required InAppMessageType messageType,
InAppMessageAction? action,
InAppMessageAction? primaryAction,
}) {
return InAppMessage(
campaignMetadata: const InAppMessagingCampaignMetadata(
campaignId: 'c1',
campaignName: 'promo',
isTestMessage: false,
),
messageType: messageType,
action: action,
primaryAction: primaryAction,
onImpress: () async => reported.add('impress'),
onClick: (InAppMessageAction a) async => reported.add('click'),
onDismiss: (InAppMessagingDismissType t) async => reported.add('dismiss'),
onError: (String r) async => reported.add('error'),
);
}
/// The snippet from docs/in-app-messaging/_customize-messages.md, verbatim.
Future<void> docSnippet(InAppMessage message) async {
await message.impress();
await message.click(message.primaryAction ?? message.action!);
await message.dismiss();
}
test('image-only campaign with no action: snippet throws, nothing terminal '
'is reported', () async {
final InAppMessage message =
buildMessage(messageType: InAppMessageType.imageOnly);
await expectLater(docSnippet(message), throwsA(isA<TypeError>()));
// No click, no dismiss, no reportError: the message is never resolved.
expect(reported, <String>['impress']);
});
test('user taps nothing: snippet reports a click and never reports the '
'dismiss', () async {
final InAppMessage message = buildMessage(
messageType: InAppMessageType.card,
primaryAction: const InAppMessageAction(id: 'a1'),
);
await docSnippet(message);
// 'click' is reported though nothing was tapped, and click() ran first,
// so the following dismiss() was a no-op.
expect(reported, <String>['impress', 'click']);
});
}Both tests pass against Suggested replacement for the docs snippet: FirebaseInAppMessaging.instance.onMessageDisplay.listen((message) async {
await message.impress();
// Both are null for a campaign published without an action.
final action = message.primaryAction ?? message.action;
// showCampaign() is your own widget; report the click from its tap handler.
await showCampaign(
message,
onActionTap: action == null
? null
: () async {
await message.click(action);
// The plugin does not open action URLs — your app should.
},
);
await message.dismiss();
});
await FirebaseInAppMessaging.instance.setCustomDisplayEnabled(true);It would also help to state in the docs that For what it's worth, the package README has the same |
Description
Fixes three event bugs in the lifecycle events (#18584) and custom display (#18586) added in 0.10.0.
1. Android: event listeners stop after the first activity pause.
The SDK's default display removes every listener on each activity pause. The plugin added them only once, so after the app went to the background,
onMessageClicked,onMessageImpression,onMessageDismissedandonMessageDisplayErrorstayed silent. Fix: the plugin adds them again when an activity resumes.2. Messages sent to
onMessageDisplayare lost when nothing listens yet.On iOS, the SDK then waits forever for a click, dismiss or error, and shows no other campaign. Fix: a message is held for the first listener. If nobody listens within 5 seconds, or a newer campaign replaces it:
The docs now say to listen to
onMessageDisplaybefore enabling custom display.3. Android: turning off custom display when it is already off flickers the default display.
It now does nothing in that case.
Tests
method_channel_firebase_in_app_messaging_test.dart, run as Android and iOS): a message sent before the first listener reaches it; on iOS an unheard or replaced message is reported as a display error; on Android it is dropped without a report.FirebaseInAppMessagingPluginTest:listenersAreAddedAgainWhenAnActivityResumesfails without fix 1.disablingCustomDisplayThatIsOff_leavesTheDefaultDisplayAloneandonDetachedFromEngine_withCustomDisplayOff_leavesTheDefaultDisplayAlonefail without fix 3.EventListenerRegistrationTestcovers when listeners are added and removed.android_unit_tests.yamlnow also runs:firebase_in_app_messaging:testDebugUnitTest.Related Issues
Follow-up to #18584 and #18586.
Checklist
///).melos run analyze) does not report any problems on my PR.Breaking Change