Skip to content

Commit e2999ee

Browse files
authored
Merge pull request NativeScript#2323 from NativeScript/raikov/fix-2256
Fixed: Custom ActionItem gets displaced in IOS
2 parents 33dd9a6 + 6f241ff commit e2999ee

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

tns-core-modules/ui/action-bar/action-bar.ios.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,11 @@ export class ActionBar extends common.ActionBar {
139139
var barButtonItem: UIBarButtonItem;
140140

141141
if (item.actionView && item.actionView.ios) {
142-
let buttonView: UIButton = UIButton.buttonWithType(UIButtonType.UIButtonTypeSystem);
143-
// Disable the interaction of the custom view so that the tap event of the button is triggered
144-
(<UIView>item.actionView.ios).userInteractionEnabled = false;
145-
146-
buttonView.addTargetActionForControlEvents(tapHandler, "tap", UIControlEvents.UIControlEventTouchUpInside);
147-
buttonView.frame = CGRectMake(0, 0, item.actionView.getMeasuredWidth(), item.actionView.getMeasuredHeight());
148-
buttonView.addSubview(item.actionView.ios);
149-
barButtonItem = UIBarButtonItem.alloc().initWithCustomView(buttonView);
142+
if (item.hasListeners(ActionItem.tapEvent)) {
143+
var recognizer = UITapGestureRecognizer.alloc().initWithTargetAction(tapHandler, "tap");
144+
item.actionView.ios.addGestureRecognizer(recognizer);
145+
}
146+
barButtonItem = UIBarButtonItem.alloc().initWithCustomView(item.actionView.ios);
150147
}
151148
else if (types.isNumber(item.ios.systemIcon)) {
152149
barButtonItem = UIBarButtonItem.alloc().initWithBarButtonSystemItemTargetAction(item.ios.systemIcon, tapHandler, "tap");
@@ -244,16 +241,12 @@ export class ActionBar extends common.ActionBar {
244241
if (actionItem.actionView && actionItem.actionView.ios) {
245242
let measuredWidth = actionItem.actionView.getMeasuredWidth();
246243
let measuredHeight = actionItem.actionView.getMeasuredHeight();
247-
let buttonView = (<UIView>actionItem.actionView.ios).superview;
248-
249244
view.View.layoutChild(this, actionItem.actionView, 0, 0, measuredWidth, measuredHeight);
250-
if (buttonView) {
251-
buttonView.frame = CGRectMake(0, 0, measuredWidth, measuredHeight);
252-
}
253245
}
254246
});
255247

256248
super.onLayout(left, top, right, bottom);
249+
this.ios.setNeedsLayout();
257250
}
258251

259252
public layoutNativeView(left: number, top: number, right: number, bottom: number) {

0 commit comments

Comments
 (0)