Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## Unreleased

- `ShowToastAction` (`ActionType.showToast`): shows a short message at the
bottom of the screen, with an optional icon, colors, duration and offset.
- Every node with fills, strokes or opacity now lists `fill`, `stroke` and
`opacity` in its property variables, and every node lists `width` and
`height`, so conditions, bound variables and set value actions can change
them at runtime.

## 5.2.0

### New actions
Expand Down
18 changes: 18 additions & 0 deletions lib/src/api/mixins.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1044,9 +1044,27 @@ mixin VariablePropertiesMixin {
mixin PropertyVariableMixin on BaseNode {
/// Properties of the node that can be used in actions or can be changed by
/// an action.
///
/// Style properties (fill, stroke, opacity, width, height; a text's fill is
/// its color) can be set by
/// conditions, bound to variables or formulas, or changed by a set value
/// action, on any node that has them.
late final List<ValueModel> propertyVariables = [
BoolValue(name: 'visible', value: visible),
IntValue(name: 'rotationDegrees', value: rotationDegrees),
if (this case final GeometryMixin geometry) ...[
PaintValue(name: 'fill', value: geometry.fills.firstOrNull),
PaintValue(name: 'stroke', value: geometry.strokes.firstOrNull),
],
if (this case final TextNode text)
PaintValue(
name: 'fill',
value: text.textMixedProps.firstOrNull?.fills.firstOrNull,
),
if (this case final BlendMixin blend)
DoubleValue(name: 'opacity', value: blend.opacity),
DoubleValue(name: 'width', value: basicBoxLocal.width),
DoubleValue(name: 'height', value: basicBoxLocal.height),
];
}

Expand Down
9 changes: 8 additions & 1 deletion lib/src/api/models/action/action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ enum ActionType {
forEach,

/// Upload or delete files in cloud storage.
cloudFiles;
cloudFiles,

/// Show a short message near the bottom of the screen.
showToast;

/// Displayable string representation of the [ActionType].
String get prettify {
Expand Down Expand Up @@ -86,6 +89,8 @@ enum ActionType {
return 'For Each';
case ActionType.cloudFiles:
return 'Cloud Files';
case ActionType.showToast:
return 'Show Toast';
}
}
}
Expand Down Expand Up @@ -167,6 +172,8 @@ abstract class ActionModel with SerializableMixin {
return ForEachAction.fromJson(json);
case ActionType.cloudFiles:
return CloudFilesAction.fromJson(json);
case ActionType.showToast:
return ShowToastAction.fromJson(json);
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/src/api/models/action/api_call_action.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/src/api/models/action/auth_action.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/src/api/models/action/call_function_action.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/src/api/models/action/cloud_files_action.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/src/api/models/action/conditional_action.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/src/api/models/action/for_each_action.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/src/api/models/action/link_action.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/src/api/models/action/navigation_action.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/src/api/models/action/set_cloud_storage_action.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/src/api/models/action/set_storage_action.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/src/api/models/action/set_value_action.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/src/api/models/action/set_variable_action.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/src/api/models/action/set_variant_action.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/src/api/models/action/show_dialog_action.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 83 additions & 0 deletions lib/src/api/models/action/show_toast_action.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:equatable/equatable.dart';

import '../../mixins.dart';
import '../models.dart';

part 'show_toast_action.g.dart';

/// An action that shows a short message in a pill near the bottom of the
/// screen, then hides it.
@JsonSerializable()
class ShowToastAction extends ActionModel with Equatable, SerializableMixin {
/// The message. Supports variables and formulas, e.g.
/// `Added ${storage.drink.name} to your order`.
final String message;

/// How long the message stays on screen, in milliseconds.
final int duration;

/// Pill color.
final ColorRGBA backgroundColor;

/// Message color.
final ColorRGBA textColor;

/// Optional icon before the message.
final MultiSourceIconModel? icon;

/// Distance from the bottom of the screen.
final double bottomOffset;

/// Creates a new [ShowToastAction].
ShowToastAction({
required this.message,
this.duration = 2600,
this.backgroundColor = const ColorRGBA(r: 0.169, g: 0.141, b: 0.125, a: 1),
this.textColor = ColorRGBA.white,
this.icon,
this.bottomOffset = 104,
super.nonBlocking,
super.enabled,
}) : super(type: ActionType.showToast);

@override
List<Object?> get props => [
message,
duration,
backgroundColor,
textColor,
icon,
bottomOffset,
];

/// Duplicates this [ShowToastAction] with given data overrides.
ShowToastAction copyWith({
String? message,
int? duration,
ColorRGBA? backgroundColor,
ColorRGBA? textColor,
MultiSourceIconModel? icon,
bool clearIcon = false,
double? bottomOffset,
}) => ShowToastAction(
message: message ?? this.message,
duration: duration ?? this.duration,
backgroundColor: backgroundColor ?? this.backgroundColor,
textColor: textColor ?? this.textColor,
icon: clearIcon ? null : icon ?? this.icon,
bottomOffset: bottomOffset ?? this.bottomOffset,
nonBlocking: nonBlocking,
enabled: enabled,
);

/// Creates a new [ShowToastAction] instance from JSON data.
factory ShowToastAction.fromJson(Map json) => _$ShowToastActionFromJson(json);

@override
Map toJson() =>
_$ShowToastActionOmitDefaults(this, _$ShowToastActionToJson(this));

@override
R? accept<R>(ActionVisitor<R> visitor) => visitor.visitShowToastAction(this);
}
79 changes: 79 additions & 0 deletions lib/src/api/models/action/show_toast_action.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/src/api/models/action/submit_action.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions lib/src/api/models/condition.dart
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,9 @@ abstract interface class ActionVisitor<R> {
/// Evaluates the action and returns the result.
R? visitLinkAction(LinkAction action);

/// Evaluates the action and returns the result.
R? visitShowToastAction(ShowToastAction action);

/// Evaluates the action and returns the result.
R? visitCallFunctionAction(CallFunctionAction action);

Expand Down
1 change: 1 addition & 0 deletions lib/src/api/models/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export 'action/conditional_action.dart';
export 'action/for_each_action.dart';
export 'action/call_function_action.dart';
export 'action/link_action.dart';
export 'action/show_toast_action.dart';
export 'action/load_from_cloud_storage_action.dart';
export 'action/navigation_action.dart';
export 'action/set_cloud_storage_action.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/src/api/nodes/frame_node.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/src/api/nodes/page_view_node.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/src/api/nodes/variance_node.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading