Skip to content

Commit 81ee1ee

Browse files
authored
Merge pull request #1868 from EnsembleUI/BottomNavbar-Eval-1855
Added Switch screen evaluation for BottomNavbar
2 parents ffa9a60 + b0a180a commit 81ee1ee

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

modules/ensemble/lib/framework/menu.dart

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ abstract class Menu extends Object with HasStyles, Invokable {
9191
floatingAlignment:
9292
Utils.optionalString(item['floatingAlignment']) ?? 'center',
9393
floatingMargin: Utils.optionalInt(item['floatingMargin']),
94-
switchScreen: Utils.getBool(item['switchScreen'], fallback: true),
94+
switchScreen: item['switchScreen'],
9595
isClickable: Utils.getBool(item['isClickable'], fallback: true),
9696
onTap: item['onTap'],
9797
onTapHaptic: Utils.optionalString(item['onTapHaptic']),
@@ -174,6 +174,10 @@ abstract class Menu extends Object with HasStyles, Invokable {
174174
static List<MenuItem> getVisibleMenuItems(DataContext context, List<MenuItem> items) {
175175
return items.where((item) => item.isVisible(context)).toList();
176176
}
177+
static bool evalSwitchScreen(DataContext context, MenuItem item) {
178+
print(item.shouldSwitchScreen(context));
179+
return item.shouldSwitchScreen(context);
180+
}
177181
}
178182

179183
class BottomNavBarMenu extends Menu {
@@ -291,7 +295,7 @@ class MenuItem {
291295
this.iconLibrary,
292296
this.selected,
293297
this.floating = false,
294-
this.switchScreen = true,
298+
this.switchScreen,
295299
this.isClickable = true,
296300
this.floatingAlignment = 'center',
297301
this.floatingMargin,
@@ -310,7 +314,7 @@ class MenuItem {
310314
final String? iconLibrary;
311315
final dynamic selected;
312316
final bool floating;
313-
final bool switchScreen;
317+
final dynamic switchScreen;
314318
final bool isClickable;
315319
final String floatingAlignment;
316320
final int? floatingMargin;
@@ -331,4 +335,17 @@ class MenuItem {
331335
throw LanguageError('Failed to eval $visible');
332336
}
333337
}
338+
339+
bool shouldSwitchScreen(DataContext context) {
340+
if (switchScreen == null) return true; // Default to true if not specified
341+
if (switchScreen is bool) return switchScreen;
342+
343+
// Evaluate the dynamic condition
344+
try {
345+
var result = context.eval(switchScreen);
346+
return result is bool ? result : true;
347+
} catch (e) {
348+
throw LanguageError('Failed to eval switchScreen: $switchScreen');
349+
}
350+
}
334351
}

modules/ensemble/lib/framework/view/bottom_nav_page_group.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ class _BottomNavPageGroupState extends State<BottomNavPageGroup>
302302
activeIcon: activeIcon,
303303
isCustom: isCustom,
304304
text: label,
305-
switchScreen: item.switchScreen,
305+
switchScreen: Menu.evalSwitchScreen(widget.scopeManager.dataContext, item),
306306
onTap: EnsembleAction.from(item.onTap),
307307
onTapHaptic: item.onTapHaptic,
308308
),

0 commit comments

Comments
 (0)