Skip to content

Commit

Permalink
Merge branch 'main' into footer_change
Browse files Browse the repository at this point in the history
  • Loading branch information
snehmehta committed Dec 11, 2023
2 parents d6a98b9 + 782018b commit a402a09
Show file tree
Hide file tree
Showing 15 changed files with 244 additions and 522 deletions.
2 changes: 1 addition & 1 deletion .android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
org.gradle.jvmargs=-Xmx1536M
org.gradle.jvmargs=-Xmx4G
android.useAndroidX=true
android.enableJetifier=true
4 changes: 4 additions & 0 deletions assets/schema/ensemble_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@
"type": "boolean",
"description": "Specify if the content of this screen is scrollable with a global scrollbar. Using this also allow you to customize the scrolling experience of the header."
},
"unfocus": {
"type": "boolean",
"description": "Specify if the keyboard should dismissed automatically when tapping in the non interactive widgets. Default (false)"
},
"showNavigationIcon": {
"type": "boolean",
"description": "For a screen with header, the App will automatically show the Menu, Back, or Close icon (for modal screen) before the title. On modal screen without the header, the Close icon will be shown. Set this flag to false if you wish to hide the icons and handle the navigation yourself."
Expand Down
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
28 changes: 14 additions & 14 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 @@ -68,15 +64,19 @@ class ShowBottomModalAction extends EnsembleAction {

if (widget != null) {
showModalBottomSheet(
context: context,
backgroundColor: _backgroundColor(scopeManager),
barrierColor: _barrierColor(scopeManager),
isScrollControlled: true,
enableDrag: _enableDrag(scopeManager),
showDragHandle: _enableDragHandler(scopeManager),
builder: (modalContext) =>
ContextScopeWidget(rootContext: modalContext, child: widget!))
.then((payload) {
context: context,
backgroundColor: _backgroundColor(scopeManager),
barrierColor: _barrierColor(scopeManager),
isScrollControlled: true,
enableDrag: _enableDrag(scopeManager),
showDragHandle: _enableDragHandler(scopeManager),
builder: (context) => Padding(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom,
),
child: ContextScopeWidget(rootContext: context, child: widget!),
),
).then((payload) {
if (onDismiss != null) {
return ScreenController().executeActionWithScope(
context, scopeManager, onDismiss!,
Expand Down Expand Up @@ -106,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));
}
}
21 changes: 0 additions & 21 deletions lib/ensemble_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,33 +117,12 @@ class EnsembleAppState extends State<EnsembleApp> with WidgetsBindingObserver {
Workmanager().initialize(callbackDispatcher, isInDebugMode: false);
initDeepLink(AppLifecycleState.resumed);
}

WidgetsBinding.instance.addPostFrameCallback((_) async {
executeCallbacks();
});
}

@override
void didChangeAppLifecycleState(AppLifecycleState state) async {
super.didChangeAppLifecycleState(state);
initDeepLink(state);
if (state == AppLifecycleState.resumed) {
executeCallbacks();
}
}

Future<void> executeCallbacks() async {
final callbacks = List.from(Ensemble().getCallbacksAfterInitialization());

callbacks.asMap().forEach((index, function) async {
// Removing a method and getting the function with index to execute it
Ensemble().getCallbacksAfterInitialization().remove(function);
try {
await Function.apply(function, null);
} catch (e) {
print('Failed to execute a method: $e');
}
});
}

void initDeepLink(AppLifecycleState state) {
Expand Down
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
30 changes: 24 additions & 6 deletions lib/framework/notification_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,36 @@ class NotificationManager {
});
_handleNotification();
});
}

void initGetInitialMessage() {
// This is called when the user taps on the notification and the app is opened from the terminated state
FirebaseMessaging.instance.getInitialMessage().then((message) {
if (message == null) return;

// TODO We need to handle the notification when the app was terminated
Ensemble.externalDataContext.addAll({
'title': message.notification?.title,
'body': message.notification?.body,
'data': message.data
});
Ensemble()
.addCallbackAfterInitialization(method: () => _handleNotification());
}).catchError((err) {
// ignore: avoid_print
print('Failed to get the remote notification');
});
}

void _handleNotification() {
Future<void> _handleNotification() async {
Map<String, dynamic>? messageData = Ensemble.externalDataContext['data'];
if (messageData?['screenId'] != null ||
messageData?['screenName'] != null) {
ScreenController().navigateToScreen(Utils.globalAppKey.currentContext!,
screenId: messageData!['screenId'],
screenName: messageData!['screenName'],
pageArgs: messageData);
ScreenController().navigateToScreen(
Utils.globalAppKey.currentContext!,
screenId: messageData!['screenId'],
screenName: messageData['screenName'],
pageArgs: messageData,
);
} else {
log('No screenId nor screenName provided on the notification. Ignoring ...');
}
Expand Down
52 changes: 26 additions & 26 deletions lib/framework/view/page.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:developer';

import 'package:ensemble/ensemble.dart';
import 'package:ensemble/framework/action.dart';
import 'package:ensemble/framework/data_context.dart';
import 'package:ensemble/framework/extensions.dart';
import 'package:ensemble/framework/menu.dart';
Expand All @@ -12,14 +11,10 @@ import 'package:ensemble/framework/view/data_scope_widget.dart';
import 'package:ensemble/framework/view/has_selectable_text.dart';
import 'package:ensemble/framework/view/page_group.dart';
import 'package:ensemble/framework/widget/icon.dart' as ensemble;
import 'package:ensemble/framework/widget/view_util.dart';
import 'package:ensemble/layout/list_view.dart' as ensemblelist;
import 'package:ensemble/layout/grid_view.dart' as ensembleGrid;
import 'package:ensemble/page_model.dart';
import 'package:ensemble/screen_controller.dart';
import 'package:ensemble/util/utils.dart';
import 'package:ensemble/widget/helpers/controllers.dart';
import 'package:ensemble/widget/helpers/widgets.dart';
import 'package:ensemble/widget/helpers/unfocus.dart';
import 'package:flutter/material.dart';

import '../widget/custom_view.dart';
Expand Down Expand Up @@ -415,26 +410,31 @@ class PageState extends State<Page>

Widget rtn = DataScopeWidget(
scopeManager: _scopeManager,
child: Scaffold(
resizeToAvoidBottomInset: true,
// slight optimization, if body background is set, let's paint
// the entire screen including the Safe Area
backgroundColor: backgroundColor,

// appBar is inside CustomScrollView if defined
appBar: fixedAppBar,
body: isScrollableView
? buildScrollablePageContent(hasDrawer)
: buildFixedPageContent(fixedAppBar != null),
bottomNavigationBar: _bottomNavBar,
drawer: _drawer,
endDrawer: _endDrawer,
bottomSheet: footerWidget,
floatingActionButton: closeModalButton,
floatingActionButtonLocation:
widget._pageModel.pageStyles?['navigationIconPosition'] == 'start'
? FloatingActionButtonLocation.startTop
: FloatingActionButtonLocation.endTop),
child: Unfocus(
isUnfocus: Utils.getBool(widget._pageModel.pageStyles?['unfocus'],
fallback: false),
child: Scaffold(
resizeToAvoidBottomInset: true,
// slight optimization, if body background is set, let's paint
// the entire screen including the Safe Area
backgroundColor: backgroundColor,

// appBar is inside CustomScrollView if defined
appBar: fixedAppBar,
body: isScrollableView
? buildScrollablePageContent(hasDrawer)
: buildFixedPageContent(fixedAppBar != null),
bottomNavigationBar: _bottomNavBar,
drawer: _drawer,
endDrawer: _endDrawer,
bottomSheet: footerWidget,
floatingActionButton: closeModalButton,
floatingActionButtonLocation:
widget._pageModel.pageStyles?['navigationIconPosition'] ==
'start'
? FloatingActionButtonLocation.startTop
: FloatingActionButtonLocation.endTop),
),
);

// selectableText at the root
Expand Down
Loading

0 comments on commit a402a09

Please sign in to comment.