Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

Commit

Permalink
[MOMMOM]: InAppMessaging
Browse files Browse the repository at this point in the history
  • Loading branch information
jeonghanjoo committed Mar 8, 2024
1 parent 44eeea0 commit 3383558
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 ];
Expand All @@ -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];
}

Expand Down
11 changes: 11 additions & 0 deletions FirebaseInAppMessaging/Sources/Flows/FIRIAMDisplayExecutor.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ + (NSString *)logStringForNilMessageDisplayComponent {
}

#pragma mark - FIRInAppMessagingDisplayDelegate methods

- (void)messageDisplayed:(FIRInAppMessagingDisplayMessage *)inAppMessage {
// Call through to app-side delegate.
__weak id<FIRInAppMessagingDisplayDelegate> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21507" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina6_5" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17703"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21505"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand All @@ -19,29 +19,45 @@
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="rA8-LH-EYm">
<rect key="frame" x="44" y="59" width="294" height="222"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="rA8-LH-EYm">
<rect key="frame" x="32" y="348" width="350" height="200"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<accessibility key="accessibilityConfiguration" identifier="image-view-in-image-only-view" label="In-app message image">
<bool key="isElement" value="YES"/>
</accessibility>
<constraints>
<constraint firstAttribute="height" constant="200" id="ibh-jf-uYF"/>
</constraints>
</imageView>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="vYW-0X-e5S">
<rect key="frame" x="313" y="42" width="40" height="40"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="top" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="vYW-0X-e5S">
<rect key="frame" x="32" y="548" width="350" height="96"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<accessibility key="accessibilityConfiguration" identifier="close-button" label="Close button"/>
<state key="normal" backgroundImage="close-with-transparency.png"/>
<constraints>
<constraint firstAttribute="height" constant="96" id="PUA-8A-ZKz"/>
</constraints>
<inset key="contentEdgeInsets" minX="0.0" minY="24" maxX="0.0" maxY="0.0"/>
<state key="normal" image="close-with-transparency.png"/>
<connections>
<action selector="closeButtonClicked:" destination="lGH-bl-7Xw" eventType="touchUpInside" id="lpP-J3-1Jc"/>
<action selector="closeButtonClicked:" destination="x01-lq-3r6" eventType="touchUpInside" id="wxI-c1-DJ3"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="vYW-0X-e5S" firstAttribute="top" secondItem="rA8-LH-EYm" secondAttribute="bottom" id="Cec-Ir-N3I"/>
<constraint firstItem="vYW-0X-e5S" firstAttribute="leading" secondItem="rA8-LH-EYm" secondAttribute="leading" id="LuO-Eg-p1x"/>
<constraint firstItem="vYW-0X-e5S" firstAttribute="trailing" secondItem="rA8-LH-EYm" secondAttribute="trailing" id="ZNB-M3-YeB"/>
<constraint firstItem="rA8-LH-EYm" firstAttribute="centerY" secondItem="ef6-R8-q1S" secondAttribute="centerY" id="ZSo-fX-3YY"/>
<constraint firstAttribute="trailing" secondItem="rA8-LH-EYm" secondAttribute="trailing" constant="32" id="iVF-aD-sgw"/>
<constraint firstItem="rA8-LH-EYm" firstAttribute="leading" secondItem="ef6-R8-q1S" secondAttribute="leading" constant="32" id="oFo-JA-580"/>
</constraints>
</view>
<connections>
<outlet property="closeButton" destination="vYW-0X-e5S" id="330-bY-24I"/>
<outlet property="imageView" destination="rA8-LH-EYm" id="Tdt-7e-Mi5"/>
<outlet property="imageViewHeightConstraint" destination="ibh-jf-uYF" id="Ap9-Af-6a8"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="NZ8-Cx-8wo" userLabel="First Responder" sceneMemberID="firstResponder"/>
Expand Down Expand Up @@ -387,8 +403,8 @@
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view clipsSubviews="YES" contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Aft-rr-icV" userLabel="Card view">
<rect key="frame" x="87" y="87" width="240" height="240"/>
<view clipsSubviews="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Aft-rr-icV" userLabel="Card view">
<rect key="frame" x="87" y="84" width="240" height="728"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="gB0-8W-G9z">
<rect key="frame" x="0.0" y="0.0" width="240" height="160"/>
Expand Down Expand Up @@ -455,8 +471,8 @@
<constraint firstItem="elG-N9-aqH" firstAttribute="width" secondItem="Tmr-ar-k7h" secondAttribute="width" id="dXF-bM-hYF"/>
</constraints>
</scrollView>
<button opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" horizontalCompressionResistancePriority="251" verticalCompressionResistancePriority="1000" ambiguous="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="aZE-3x-WHk" userLabel="Primary action button">
<rect key="frame" x="163" y="186" width="53" height="30"/>
<button opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" horizontalCompressionResistancePriority="251" verticalCompressionResistancePriority="1000" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="aZE-3x-WHk" userLabel="Primary action button">
<rect key="frame" x="163" y="674" width="53" height="30"/>
<accessibility key="accessibilityConfiguration" identifier="card-primary-action-button"/>
<constraints>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="44" id="pxm-yD-xhm"/>
Expand All @@ -466,8 +482,8 @@
<action selector="primaryActionButtonTapped:" destination="oTF-1C-LZP" eventType="touchUpInside" id="Jk0-dp-Qgj"/>
</connections>
</button>
<button hidden="YES" opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" horizontalCompressionResistancePriority="250" verticalCompressionResistancePriority="1000" ambiguous="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Feg-VM-jUf" userLabel="Secondary action button">
<rect key="frame" x="65" y="186" width="74" height="30"/>
<button hidden="YES" opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" horizontalCompressionResistancePriority="250" verticalCompressionResistancePriority="1000" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Feg-VM-jUf" userLabel="Secondary action button">
<rect key="frame" x="65" y="674" width="74" height="30"/>
<accessibility key="accessibilityConfiguration" identifier="card-secondary-action-button"/>
<constraints>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="44" id="bpF-9w-pDe"/>
Expand Down Expand Up @@ -593,6 +609,6 @@
</scene>
</scenes>
<resources>
<image name="close-with-transparency.png" width="44" height="44"/>
<image name="close-with-transparency.png" width="32" height="32"/>
</resources>
</document>
Binary file modified FirebaseInAppMessaging/iOS/Resources/close-with-transparency.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified FirebaseInAppMessaging/iOS/Resources/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3383558

Please sign in to comment.