From 3383558f76e0f4da501668b5befe8352d5239584 Mon Sep 17 00:00:00 2001 From: Jeonghan Joo Date: Sat, 9 Mar 2024 02:52:20 +0900 Subject: [PATCH] [MOMMOM]: InAppMessaging --- .../FIRIAMBaseRenderingViewController.m | 3 + .../ImageOnly/FIRIAMImageOnlyViewController.m | 68 ++++-------------- .../Sources/Flows/FIRIAMDisplayExecutor.m | 11 +++ .../FIRInAppMessagingRendering.h | 7 ++ ...IRInAppMessageDisplayStoryboard.storyboard | 48 ++++++++----- .../iOS/Resources/close-with-transparency.png | Bin 379 -> 222 bytes .../Resources/close-with-transparency@2x.png | Bin 837 -> 279 bytes .../Resources/close-with-transparency@3x.png | Bin 0 -> 372 bytes 8 files changed, 67 insertions(+), 70 deletions(-) create mode 100644 FirebaseInAppMessaging/iOS/Resources/close-with-transparency@3x.png diff --git a/FirebaseInAppMessaging/Sources/DefaultUI/FIRIAMBaseRenderingViewController.m b/FirebaseInAppMessaging/Sources/DefaultUI/FIRIAMBaseRenderingViewController.m index f05fe050e3d..37e18fe198a 100644 --- a/FirebaseInAppMessaging/Sources/DefaultUI/FIRIAMBaseRenderingViewController.m +++ b/FirebaseInAppMessaging/Sources/DefaultUI/FIRIAMBaseRenderingViewController.m @@ -74,6 +74,9 @@ - (void)viewDidLoad { - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self impressionStartCheckpoint]; + if (self.inAppMessage && [self.displayDelegate respondsToSelector:@selector(messageDisplayed:)]) { + [self.displayDelegate messageDisplayed:self.inAppMessage]; + } } - (void)viewDidDisappear:(BOOL)animated { diff --git a/FirebaseInAppMessaging/Sources/DefaultUI/ImageOnly/FIRIAMImageOnlyViewController.m b/FirebaseInAppMessaging/Sources/DefaultUI/ImageOnly/FIRIAMImageOnlyViewController.m index ffc37a408ec..600a7e43e24 100644 --- a/FirebaseInAppMessaging/Sources/DefaultUI/ImageOnly/FIRIAMImageOnlyViewController.m +++ b/FirebaseInAppMessaging/Sources/DefaultUI/ImageOnly/FIRIAMImageOnlyViewController.m @@ -26,6 +26,9 @@ @interface FIRIAMImageOnlyViewController () @property(weak, nonatomic) IBOutlet UIImageView *imageView; @property(weak, nonatomic) IBOutlet UIButton *closeButton; +@property(weak, nonatomic) IBOutlet NSLayoutConstraint *imageViewHeightConstraint; + + @property(nonatomic, assign) CGSize imageOriginalSize; @end @@ -87,7 +90,7 @@ - (void)messageTapped:(UITapGestureRecognizer *)recognizer { - (void)viewDidLoad { [super viewDidLoad]; - [self.view setBackgroundColor:[UIColor.grayColor colorWithAlphaComponent:0.5]]; + [self.view setBackgroundColor:[UIColor.blackColor colorWithAlphaComponent:0.7]]; // Close button should be announced last for better VoiceOver experience. self.view.accessibilityElements = @[ self.imageView, self.closeButton ]; @@ -111,60 +114,17 @@ - (void)viewDidLayoutSubviews { if (!self.imageOnlyMessage.imageData) { return; } - - // do the calculation in viewDidLayoutSubViews since self.view.window.frame is only - // reliable at this time - - // Calculate the size of the image view under the constraints: - // 1 Retain the image ratio - // 2 Have at least 30 point of margines around four sides of the image view - - CGFloat minimalMargine = 30; // 30 points - CGFloat maxImageViewWidth = self.view.window.frame.size.width - minimalMargine * 2; - CGFloat maxImageViewHeight = self.view.window.frame.size.height - minimalMargine * 2; - - // Factor in space for the top notch on iPhone X*. -#if defined(__IPHONE_11_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 - if (@available(iOS 11.0, *)) { - maxImageViewHeight -= self.view.safeAreaInsets.top; - } -#endif // defined(__IPHONE_11_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 - - CGFloat adjustedImageViewHeight = self.imageOriginalSize.height; - CGFloat adjustedImageViewWidth = self.imageOriginalSize.width; - - if (adjustedImageViewWidth > maxImageViewWidth || adjustedImageViewHeight > maxImageViewHeight) { - if (maxImageViewHeight / maxImageViewWidth > - self.imageOriginalSize.height / self.imageOriginalSize.width) { - // the image is relatively too wide compared against displayable area - adjustedImageViewWidth = maxImageViewWidth; - adjustedImageViewHeight = - adjustedImageViewWidth * self.imageOriginalSize.height / self.imageOriginalSize.width; - - FIRLogDebug(kFIRLoggerInAppMessagingDisplay, @"I-FID110002", - @"Use max available image display width as %lf", adjustedImageViewWidth); - } else { - // the image is relatively too narrow compared against displayable area - adjustedImageViewHeight = maxImageViewHeight; - adjustedImageViewWidth = - adjustedImageViewHeight * self.imageOriginalSize.width / self.imageOriginalSize.height; - FIRLogDebug(kFIRLoggerInAppMessagingDisplay, @"I-FID110003", - @"Use max avilable image display height as %lf", adjustedImageViewHeight); + + if (CGSizeEqualToSize(self.imageOriginalSize, CGSizeZero)) { + return; } - } else { - // image can be rendered fully at its original size - FIRLogDebug(kFIRLoggerInAppMessagingDisplay, @"I-FID110001", - @"Image can be fully displayed in image only mode"); - } - - CGRect rect = CGRectMake(0, 0, adjustedImageViewWidth, adjustedImageViewHeight); - self.imageView.frame = rect; - self.imageView.center = self.view.center; - - CGFloat closeButtonCenterX = CGRectGetMaxX(self.imageView.frame); - CGFloat closeButtonCenterY = CGRectGetMinY(self.imageView.frame); - self.closeButton.center = CGPointMake(closeButtonCenterX, closeButtonCenterY); - + + CGFloat ratio = self.imageOriginalSize.height / self.imageOriginalSize.width; + + CGFloat width = self.imageView.frame.size.width; + CGFloat height = width * ratio; + self.imageViewHeightConstraint.constant = height; + [self.view bringSubviewToFront:self.closeButton]; } diff --git a/FirebaseInAppMessaging/Sources/Flows/FIRIAMDisplayExecutor.m b/FirebaseInAppMessaging/Sources/Flows/FIRIAMDisplayExecutor.m index 28ae23fb562..c55fe5a5300 100644 --- a/FirebaseInAppMessaging/Sources/Flows/FIRIAMDisplayExecutor.m +++ b/FirebaseInAppMessaging/Sources/Flows/FIRIAMDisplayExecutor.m @@ -67,6 +67,17 @@ + (NSString *)logStringForNilMessageDisplayComponent { } #pragma mark - FIRInAppMessagingDisplayDelegate methods + +- (void)messageDisplayed:(FIRInAppMessagingDisplayMessage *)inAppMessage { + // Call through to app-side delegate. + __weak id appSideDelegate = self.inAppMessaging.delegate; + if ([appSideDelegate respondsToSelector:@selector(messageDisplayed:)]) { + [appSideDelegate messageDisplayed:inAppMessage]; + } +} + + + - (void)messageClicked:(FIRInAppMessagingDisplayMessage *)inAppMessage withAction:(FIRInAppMessagingAction *)action { // Call through to app-side delegate. diff --git a/FirebaseInAppMessaging/Sources/Public/FirebaseInAppMessaging/FIRInAppMessagingRendering.h b/FirebaseInAppMessaging/Sources/Public/FirebaseInAppMessaging/FIRInAppMessagingRendering.h index b32226103ac..1bb704a3717 100644 --- a/FirebaseInAppMessaging/Sources/Public/FirebaseInAppMessaging/FIRInAppMessagingRendering.h +++ b/FirebaseInAppMessaging/Sources/Public/FirebaseInAppMessaging/FIRInAppMessagingRendering.h @@ -459,6 +459,13 @@ NS_SWIFT_NAME(InAppMessagingDisplayDelegate) @optional +/** + * Called when the message is displayed on the screen. + * @param inAppMessage the message that was displayed. + */ +- (void)messageDisplayed:(FIRInAppMessagingDisplayMessage *)inAppMessage; + + /** * Called when the message is dismissed. Should be called from main thread. * @param inAppMessage the message that was dismissed. diff --git a/FirebaseInAppMessaging/iOS/Resources/FIRInAppMessageDisplayStoryboard.storyboard b/FirebaseInAppMessaging/iOS/Resources/FIRInAppMessageDisplayStoryboard.storyboard index 0c8e5ddf907..c833ad4567b 100644 --- a/FirebaseInAppMessaging/iOS/Resources/FIRInAppMessageDisplayStoryboard.storyboard +++ b/FirebaseInAppMessaging/iOS/Resources/FIRInAppMessageDisplayStoryboard.storyboard @@ -1,9 +1,9 @@ - + - + @@ -19,18 +19,25 @@ - - - + + + + + + - + + + + + + + + + @@ -387,8 +403,8 @@ - - + + @@ -455,8 +471,8 @@ - -