Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to use actions in js using ensemble object #1037

Merged
merged 14 commits into from
Dec 7, 2023
12 changes: 1 addition & 11 deletions lib/action/bottom_modal_action.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:ui';

import 'package:ensemble/framework/action.dart';
import 'package:ensemble/framework/data_context.dart';
import 'package:ensemble/framework/error_handling.dart';
Expand All @@ -9,9 +7,7 @@ import 'package:ensemble/framework/view/context_scope_widget.dart';
import 'package:ensemble/screen_controller.dart';
import 'package:ensemble/util/utils.dart';
import 'package:ensemble_ts_interpreter/invokables/invokable.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:yaml/yaml.dart';

/// open a Modal Bottom Sheet
class ShowBottomModalAction extends EnsembleAction {
Expand Down Expand Up @@ -100,12 +96,6 @@ class DismissBottomModalAction extends EnsembleAction {
@override
Future<dynamic> execute(BuildContext context, ScopeManager scopeManager,
{DataContext? dataContext}) {
BuildContext? bottomModalContext =
ContextScopeWidget.getRootContext(context);
if (bottomModalContext != null) {
return Navigator.maybePop(
bottomModalContext, scopeManager.dataContext.eval(payload));
}
return Future.value(null);
return Navigator.maybePop(context, scopeManager.dataContext.eval(payload));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this will only work for the simplest use case where the widget is defined directly in the same block. The context here can belong to a deeply nested widget - hence the reason we want to travel up to the root to dismiss the dialog.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay @vusters, actually ContextScopeWidget.getRootContext(context) was returning null, so the dialog was never dismissed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nehal076 figure out a solution that takes into account the fact that sometimes this could be deeply nested.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vusters we don't really travel up to the root, we were just checking the root and ignoring all other contexts and that is incorrect and did not work.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vusters I've done this, if the rootContext is not null, it will use root context, else it will use the local context to dismiss the modal

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this works even when called from deeply nested widget?

}
}