NativeScript / ios-jsc

NativeScript for iOS using JavaScriptCore
http://docs.nativescript.org/runtimes/ios
Apache License 2.0
298 stars 59 forks source link

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

Closed manoldonev closed 4 years ago

manoldonev commented 4 years ago

Environment

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.

mbektchiev commented 4 years ago

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);
            }
        }