Skip to content

Commit

Permalink
Merge pull request #1037 from EnsembleUI/971-actions-in-js
Browse files Browse the repository at this point in the history
Ability to use actions in js using ensemble object
  • Loading branch information
kmahmood74 authored Dec 7, 2023
2 parents 038e9a7 + d56fa0d commit 2b5d9b9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
4 changes: 3 additions & 1 deletion lib/action/action_invokable.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:ensemble/action/call_external_method.dart';
import 'package:ensemble/framework/action.dart';
import 'package:ensemble/framework/error_handling.dart';
import 'package:ensemble/framework/scope.dart';
Expand All @@ -22,6 +21,9 @@ abstract class ActionInvokable with Invokable {
ActionType.copyToClipboard,
ActionType.getDeviceToken,
ActionType.getPhoneContacts,
ActionType.showBottomModal,
ActionType.dismissBottomModal,
ActionType.showDialog,
]);
}

Expand Down
6 changes: 1 addition & 5 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 @@ -110,6 +106,6 @@ class DismissBottomModalAction extends EnsembleAction {
return Navigator.maybePop(
bottomModalContext, scopeManager.dataContext.eval(payload));
}
return Future.value(null);
return Navigator.maybePop(context, scopeManager.dataContext.eval(payload));
}
}
18 changes: 10 additions & 8 deletions lib/framework/action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import 'package:ensemble/framework/extensions.dart';
import 'package:ensemble/framework/keychain_manager.dart';
import 'package:ensemble/framework/permissions_manager.dart';
import 'package:ensemble/framework/scope.dart';
import 'package:ensemble/framework/view/bottom_nav_page_group.dart';
import 'package:ensemble/framework/view/page_group.dart';
import 'package:ensemble/framework/widget/view_util.dart';
import 'package:ensemble/receive_intent_manager.dart';
Expand Down Expand Up @@ -67,17 +66,20 @@ class ShowDialogAction extends EnsembleAction {
final Map<String, dynamic>? options;
final EnsembleAction? onDialogDismiss;

factory ShowDialogAction.fromYaml({Invokable? initiator, Map? payload}) {
factory ShowDialogAction.from({Invokable? initiator, Map? payload}) {
if (payload == null || payload['widget'] == null) {
throw LanguageError(
"${ActionType.showDialog.name} requires the 'widget' for the Dialog's content.");
}
return ShowDialogAction(
initiator: initiator,
widget: payload['widget'],
//inputs: Utils.getMap(payload["inputs"]),
options: Utils.getMap(payload['options']),
onDialogDismiss: EnsembleAction.fromYaml(payload['onDialogDismiss']));
initiator: initiator,
widget: payload['widget'],
//inputs: Utils.getMap(payload["inputs"]),
options: Utils.getMap(payload['options']),
onDialogDismiss: payload['onDialogDismiss'] == null
? null
: EnsembleAction.fromYaml(payload['onDialogDismiss']),
);
}
}

Expand Down Expand Up @@ -1006,7 +1008,7 @@ abstract class EnsembleAction {
} else if (actionType == ActionType.openCamera) {
return ShowCameraAction.fromYaml(initiator: initiator, payload: payload);
} else if (actionType == ActionType.showDialog) {
return ShowDialogAction.fromYaml(initiator: initiator, payload: payload);
return ShowDialogAction.from(initiator: initiator, payload: payload);
} else if (actionType == ActionType.closeAllDialogs) {
return CloseAllDialogsAction();
} else if (actionType == ActionType.startTimer) {
Expand Down
21 changes: 16 additions & 5 deletions lib/framework/data_context.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import 'dart:async';
import 'dart:convert';
import 'dart:developer';
import 'dart:io' as io;
import 'dart:ui';
import 'package:ensemble/action/action_invokable.dart';
import 'package:ensemble/action/call_external_method.dart';
import 'package:ensemble/action/bottom_modal_action.dart';
import 'package:ensemble/action/haptic_action.dart';
import 'package:ensemble/action/invoke_api_action.dart';
import 'package:ensemble/action/misc_action.dart';
import 'package:ensemble/action/navigation_action.dart';
import 'package:ensemble/ensemble.dart';
import 'package:ensemble/ensemble_app.dart';
import 'package:ensemble/framework/all_countries.dart';
import 'package:ensemble/framework/bindings.dart';
import 'package:ensemble/framework/config.dart';
import 'package:ensemble/framework/device.dart';
import 'package:ensemble/framework/error_handling.dart';
Expand Down Expand Up @@ -365,6 +362,20 @@ class NativeInvokable extends ActionInvokable {
final scope = ScreenController().getScopeManager(buildContext);
callNativeMethod(buildContext, scope, inputs);
},
ActionType.showBottomModal.name: (inputs) =>
ScreenController().executeAction(
buildContext,
ShowBottomModalAction.from(payload: inputs),
),
ActionType.dismissBottomModal.name: (inputs) =>
ScreenController().executeAction(
buildContext,
DismissBottomModalAction.from(payload: inputs),
),
ActionType.showDialog.name: (inputs) => ScreenController()
.executeAction(buildContext, ShowDialogAction.from(payload: inputs)),
ActionType.rateApp.name: (inputs) => ScreenController()
.executeAction(buildContext, RateAppAction.from(payload: inputs)),
'connectSocket': (String socketName, Map<dynamic, dynamic>? inputs) {
connectSocket(buildContext, socketName, inputs: inputs);
},
Expand Down

0 comments on commit 2b5d9b9

Please sign in to comment.