enable static method

Future<void> enable({
  1. required List<CNTab> tabs,
  2. int selectedIndex = 0,
  3. void onTabSelected(
    1. int index
    )?,
  4. void onSearchChanged(
    1. String query
    )?,
  5. void onSearchSubmitted(
    1. String query
    )?,
  6. VoidCallback? onSearchCancelled,
  7. void onSearchActiveChanged(
    1. bool isActive
    )?,
  8. Color? tintColor,
  9. Color? unselectedTintColor,
  10. bool? isDark,
})

Enable native tab bar mode

This will replace your app's root view controller with a native UITabBarController. Your Flutter content will be displayed within the selected tab.

Only works on iOS 26+. On older versions, this is a no-op.

Implementation

static Future<void> enable({
  required List<CNTab> tabs,
  int selectedIndex = 0,
  void Function(int index)? onTabSelected,
  void Function(String query)? onSearchChanged,
  void Function(String query)? onSearchSubmitted,
  VoidCallback? onSearchCancelled,
  void Function(bool isActive)? onSearchActiveChanged,
  Color? tintColor,
  Color? unselectedTintColor,
  bool? isDark,
}) async {
  // Only works on iOS 26+
  if (defaultTargetPlatform != TargetPlatform.iOS ||
      !PlatformVersion.shouldUseNativeGlass) {
    return;
  }

  if (_isEnabled) {
    return;
  }

  // Store callbacks
  _onTabSelected = onTabSelected;
  _onSearchChanged = onSearchChanged;
  _onSearchSubmitted = onSearchSubmitted;
  _onSearchCancelled = onSearchCancelled;
  _onSearchActiveChanged = onSearchActiveChanged;

  // Setup method call handler for callbacks
  _channel.setMethodCallHandler(_handleMethodCall);

  // Enable native tab bar
  await _channel.invokeMethod('enable', {
    'tabs': tabs
        .map(
          (tab) => {
            'title': tab.title,
            'sfSymbol': tab.sfSymbol?.name,
            'activeSfSymbol': tab.activeSfSymbol?.name,
            'isSearch': tab.isSearchTab,
            'badgeCount': tab.badgeCount,
          },
        )
        .toList(),
    'selectedIndex': selectedIndex,
    'isDark': isDark ?? false,
    if (tintColor != null) 'tint': tintColor.toARGB32(),
    if (unselectedTintColor != null)
      'unselectedTint': unselectedTintColor.toARGB32(),
  });

  _isEnabled = true;
}