8080#define LPMT_ARG_HTML_WIDTH @" HTML Width"
8181#define LPMT_ARG_HTML_ALIGN @" HTML Align"
8282#define LPMT_ARG_HTML_Y_OFFSET @" HTML Y Offset"
83+ #define LPMT_ARG_HTML_TAP_OUTSIDE_TO_CLOSE @" Tap Outside to Close"
8384#define LPMT_ARG_HTML_ALIGN_TOP @" Top"
8485#define LPMT_ARG_HTML_ALIGN_BOTTOM @" Bottom"
8586#define LPMT_ARG_APP_ICON @" __iOSAppIcon"
137138static NSString *DEFAULTS_ASKED_TO_PUSH = @" __Leanplum_asked_to_push" ;
138139static NSString *DEFAULTS_LEANPLUM_ENABLED_PUSH = @" __Leanplum_enabled_push" ;
139140
141+ #pragma mark Helper View Class
142+ @interface LPHitView : UIView
143+ @property (strong , nonatomic ) void (^callback)(void );
144+ @end
145+
146+ @implementation LPHitView
147+ - (id )initWithCallback : (void (^)(void ))callback
148+ {
149+ if (self = [super init ]) {
150+ self.callback = [callback copy ];
151+ }
152+ return self;
153+ }
154+
155+ - (UIView *)hitTest : (CGPoint)point withEvent : (UIEvent *)event
156+ {
157+ UIView *hitView = [super hitTest: point withEvent: event];
158+ if (hitView == self) {
159+ if (self.callback ) {
160+ self.callback ();
161+ }
162+ return nil ;
163+ }
164+ return hitView;
165+ }
166+ @end
167+
140168@implementation LPMessageTemplatesClass {
141169 NSMutableArray *_contexts;
142170 UIView *_popupView;
@@ -148,6 +176,7 @@ @implementation LPMessageTemplatesClass {
148176 UIButton *_cancelButton;
149177 UIButton *_dismissButton;
150178 UIButton *_overlayView;
179+ LPHitView *_closePopupView;
151180 BOOL _webViewNeedsFade;
152181}
153182
@@ -458,6 +487,7 @@ - (void)defineActions
458487 [LPActionArg argNamed: LPMT_ARG_HTML_HEIGHT withNumber: @0 ],
459488 [LPActionArg argNamed: LPMT_ARG_HTML_WIDTH withString: @" 100%" ],
460489 [LPActionArg argNamed: LPMT_ARG_HTML_Y_OFFSET withString: @" 0px" ],
490+ [LPActionArg argNamed: LPMT_ARG_HTML_TAP_OUTSIDE_TO_CLOSE withBool: NO ],
461491 [LPActionArg argNamed: LPMT_HAS_DISMISS_BUTTON withBool: NO ],
462492 [LPActionArg argNamed: LPMT_ARG_HTML_TEMPLATE withFile: nil ]]
463493 withResponder: messageResponder];
@@ -776,6 +806,7 @@ - (void)closePopupWithAnimation:(BOOL)animated
776806 _popupGroup = nil ;
777807 _dismissButton = nil ;
778808 _overlayView = nil ;
809+ _closePopupView = nil ;
779810
780811 [[NSNotificationCenter defaultCenter ] removeObserver: self
781812 name: UIApplicationDidChangeStatusBarOrientationNotification
@@ -1003,6 +1034,17 @@ - (void)updatePopupLayout
10031034 if (contextArgWidth && [contextArgWidth length ] > 0 ) {
10041035 htmlWidth = [self valueFromHtmlString: contextArgWidth percentRange: screenWidth];
10051036 }
1037+
1038+ // Tap outside to close Banner
1039+ if ([context boolNamed: LPMT_ARG_HTML_TAP_OUTSIDE_TO_CLOSE]) {
1040+ _closePopupView = [[LPHitView alloc ] initWithCallback: ^{
1041+ [self dismiss ];
1042+ [_closePopupView removeFromSuperview ];
1043+ }];
1044+ _closePopupView.frame = CGRectMake (0 , 0 , screenSize.width , screenSize.height );
1045+ [[UIApplication sharedApplication ].keyWindow addSubview: _closePopupView];
1046+ [[UIApplication sharedApplication ].keyWindow bringSubviewToFront: _popupGroup];
1047+ }
10061048
10071049 CGFloat htmlX = (screenWidth - htmlWidth) / 2 .;
10081050 _popupGroup.frame = CGRectMake (htmlX, htmlY, htmlWidth, htmlHeight);
0 commit comments