NSColorPickerTouchBarItem inside NSScrubber is displayed only for 1s

Hello


I have implemented an PopoverScrubber in the macOS Touch Bar


NSPopoverTouchBarItem contains an NSTouchBar which contains NSColorPickerTouchBarItem and an NSSliderTouchBarItem


The issue is that the NSColorPickerTouchBarItem appears for 1s then is dimissed... I don't understand why. I tried to file a bug report

but it was dismissed..

The console prints:

[Layout] Detected missing constraints for <NSFunctionRowColorPickerSlider: 0x100296b20>. It cannot be placed because there are not enough constraints to fully define the size and origin. Add the missing constraints, or set translatesAutoresizingMaskIntoConstraints=YES and constraints will be generated for you. If this view is laid out manually on macOS 10.12 and later, you may choose to not call [super layout] from your override. Set a breakpoint on DETECTED_MISSING_CONSTRAINTS to debug. This error will only be logged once.


- (NSTouchBar *)makeTouchBar
{
    NSTouchBar *bar = [[NSTouchBar alloc] init];
    bar.delegate = self;
   
    [bar setCustomizationIdentifier:@"com.TouchBarCatalog.popoverScrubberViewController"];
   
    /
    bar.defaultItemIdentifiers = @[PopoverItemIdentifier, NSTouchBarItemIdentifierOtherItemsProxy];
   
    bar.customizationAllowedItemIdentifiers = @[PopoverItemIdentifier];
   
    bar.principalItemIdentifier = PopoverItemIdentifier;
   
    return bar;
}
- (nullable NSTouchBarItem *)touchBar:(NSTouchBar *)touchBar makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier
{
    if ([identifier isEqualToString:PopoverItemIdentifier])
    {
        _popoverTouchBarItem = [[NSPopoverTouchBarItem alloc] initWithIdentifier:PopoverItemIdentifier];
       
        NSScrubber *scrubber = [[NSScrubber alloc] initWithFrame:NSMakeRect(0, 0, 320, 30)];
        scrubber.delegate = self;   /
        scrubber.dataSource = self;
       
        [scrubber registerClass:[NSScrubberTextItemView class] forItemIdentifier:textScrubberInPopoverItemIdentifier];
        /
        NSScrubberLayout *scrubberLayout = [[NSScrubberFlowLayout alloc] init];
        scrubber.scrubberLayout = scrubberLayout;
       
        scrubber.mode = NSScrubberModeFree;
       
        scrubber.translatesAutoresizingMaskIntoConstraints = NO;
       
        NSScrubberSelectionStyle *outlineStyle = [NSScrubberSelectionStyle roundedBackgroundStyle];
        scrubber.selectionBackgroundStyle = outlineStyle;
       
        self.popoverTouchBarItem.collapsedRepresentation = scrubber;
       
       
       
        /
        NSTouchBar *secondaryTouchBar = [[NSTouchBar alloc] init];
        secondaryTouchBar.delegate = self;
        secondaryTouchBar.defaultItemIdentifiers =
            @[ColorPickerItemIdentifier, SliderItemIdentifier];
       
        self.popoverTouchBarItem.popoverTouchBar = secondaryTouchBar;
        self.popoverTouchBarItem.customizationLabel = @"Popover Scrubber";
       
        return self.popoverTouchBarItem;
    }
    else if ([identifier isEqualToString:SliderItemIdentifier])
    {
      _sliderTouchBarItem =
            [[NSSliderTouchBarItem alloc] initWithIdentifier:SliderItemIdentifier];
       
        _sliderTouchBarItem.slider.minValue = 0.0f;
        _sliderTouchBarItem.slider.maxValue = 10.0f;
        _sliderTouchBarItem.slider.doubleValue = 2.0f;
        _sliderTouchBarItem.target = self;
        _sliderTouchBarItem.action = @selector(sliderChanged:);
        _sliderTouchBarItem.label = @"Slider:";
       
       
       
        _sliderTouchBarItem.slider.translatesAutoresizingMaskIntoConstraints = NO;
       
       
        return _sliderTouchBarItem;
    }
   
   

   
    else if ([identifier isEqualToString:SimpleLabelItemIdentifier])
    {
        _popoverLabel = [NSTextField labelWithString:@""];  /
        NSCustomTouchBarItem *customItemForLabel =
            [[NSCustomTouchBarItem alloc] initWithIdentifier:SimpleLabelItemIdentifier];
        customItemForLabel.view = self.popoverLabel;
       
       customItemForLabel.view.translatesAutoresizingMaskIntoConstraints = YES;
        return customItemForLabel;
    }
    else if ([identifier isEqualToString:ColorPickerItemIdentifier])
    {
       
       
        self.colorPickerItem = [NSColorPickerTouchBarItem colorPickerWithIdentifier:ColorPickerItemIdentifier];
       
       
        self.colorPickerItem.view.translatesAutoresizingMaskIntoConstraints = YES;
        /
       
       /
        self.colorPickerItem.target = self;
        self.colorPickerItem.action = @selector(colorAction:);
       
       / 
      
       
        return self.colorPickerItem;
       
       
    }
    return nil;
}
- (void)colorAction:(NSColorPickerTouchBarItem *)sender
{
   
   / 
    NSLog(@"Color Chosen = %@\n", ((NSColorPickerTouchBarItem *)sender).color);
}
- (void)sliderChanged:(NSSliderTouchBarItem *)sender
{
    NSLog(@"slider changed");
}
#pragma mark - NSScrubberDataSource
NSString *textScrubberInPopoverItemIdentifier = @"textItem";
- (NSInteger)numberOfItemsForScrubber:(NSScrubber *)scrubber
{
    return 10;
}
- (NSScrubberItemView *)scrubber:(NSScrubber *)scrubber viewForItemAtIndex:(NSInteger)index
{
    NSScrubberTextItemView *itemView = [scrubber makeItemWithIdentifier:textScrubberInPopoverItemIdentifier owner:nil];
    if (index < 10)
    {
        itemView.textField.stringValue = [@(index)stringValue];
    }
    return itemView;
}
#pragma mark - NSScrubberDelegate
- (void)scrubber:(NSScrubber *)scrubber didSelectItemAtIndex:(NSInteger)selectedIndex
{
    [self.popoverTouchBarItem showPopover:self];
   
    /
    self.popoverLabel.stringValue = [NSString stringWithFormat:@"Item %ld", selectedIndex];
}

Replies

Nested popovers are currently not supported in the touch bar. (the color picker is trying to show a popover while it is inside the popover item).

Thank You!

So I should use buttons instead of an initial popover?

Will nested popovers supported in the near future?


Thanks