microsoft / fluentui-apple

UIKit and AppKit controls for building native Microsoft experiences
https://www.microsoft.com/design/fluent/#/
MIT License
908 stars 167 forks source link

UIBarButtonItem with customView doesn't work with usesLargeTitle #503

Open jpanchal opened 3 years ago

jpanchal commented 3 years ago

I am trying to use customView for rightNavigationItem along with "usesLargeTitle"

viewController.navigationItem.usesLargeTitle = true var btn: UIBarButtonItem { let button = UIButton(type: .custom) button.setImage(UIImage(named: "Alert"), for: .normal) button.frame = CGRect(x: 0, y: 0, 20, height: 20) button.addTarget(self, action: #selector(handler), for: .touchUpInside) return UIBarButtonItem(customView: button) } viewController.navigationItem.rightBarButtonItems = [btn]

So when this property is set, it hides the customView behind other blocked views. Any button set inside customView does not show in view stack.

Any suggestions?

harrieshin commented 3 years ago

Hi @jpanchal, I think you are hiring a limitation on the current largeTitle view which it tried to make it easier for clients to utilize UIBarButtonItem of the UINavigationBar but because we are redrawing/positioning barButtonStack by recreating button but there isn't a way to copy the customView of the barButtonItem to show in 2 different places. What's the scenario that you need to custom button here? You could try to create an new api in NavigationBar.swift to directly add your custom view in rightBarButtonItemsStackView.

jpanchal commented 3 years ago

Hi @harrieshin, thanks for the response. I have an alert icon in rightBarButton and I need to show a badge on top corner on this icon. In order to do that, I need to get access to this view inside rightBarButtonItems. How do I get access to the UIView which is copied inside rightBarButtonItemsStackView?

harrieshin commented 3 years ago

You would need to write code to expose that and handle marshaling between barbuttonitem and customview that client directly inserted.

jpanchal commented 3 years ago

@harrieshin is it possible currently without updating the SDK source code?