NativeScript / ios-jsc

NativeScript for iOS using JavaScriptCore

Home Page:http://docs.nativescript.org/runtimes/ios

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[iOS13] UINavigationItem.rightBarButtonItems reported as Array[] vs NSArray after items deletion

manoldonev opened this issue · comments

Environment

  • CLI: 6.2.0-2019-09-26-124011-13871 (next)
  • Cross-platform modules: 6.2.0-next-2019-09-25-140422-01 (next)
  • iOS Runtime: 6.2.0-2019-09-25-173635-01 (next)

Describe the bug
On iOS13 UINavigationItem.rightBarButtonItems is erroneously reported as empty Array[] instead of empty NSArray after removing items from it via UINavigationItem.setRightBarButtonItems:animated:. The actual call in tns-core-modules that triggers this (I think) is located here: https://github.com/NativeScript/NativeScript/blob/master/tns-core-modules/ui/action-bar/action-bar.ios.ts#L235

Sample project
See pageLoaded implementation in the following Playground project: https://play.nativescript.org/?template=play-tsc&id=LWJtcd&v=2. Note that you will need to download it locally, build it on your local workstation (with xcode11) and deploy it on iOS13 simulator as Preview app currently is not built with xcode11.

Additional context
Note this works correctly on previous iOS version -- erroneous behavior is observed only on iOS13.

For some unknown reason (optimization / refactoring / etc.) in iOS 13 they've started storing the object passed to setRightBarButtonItemsAnimated and they return it from rightBarButtonItems. Since we pass an empty JS array here, that's why we receive an empty JS Array later when we retrieve it. This doesn't happen when there are more than 0 elements in the array and that's why we receive an NSArray in that case.
I can suggest we start passing an NSArray instead of JS array like this:

        var leftBarItems = new NSMutableArray();
        var rightBarItems = new NSMutableArray();
        for (var i = 0; i < items.length; i++) {
            var barButtonItem = this.createBarButtonItem(items[i]);
            if (items[i].ios.position === "left") {
                leftBarItems.addObject(barButtonItem);
            }
            else {
                rightBarItems.insertObjectAtIndex(barButtonItem, 0);
            }
        }