Skip to content

Commit 2bf6073

Browse files
committed
Miscellaneous improvements
- Allow external components to have reactions. - Fix GestureDetector for click and long click actions not working properly. - Introduce handlesDefaultReactionsInternally to better handle external reactivity for nodes with custom properties. - Filter out disabled actions for click and long press events.
1 parent b0622ce commit 2bf6073

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

lib/src/functions/functions_repository.dart

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import 'package:rfc_6901/rfc_6901.dart';
1111
import 'package:url_launcher/url_launcher.dart';
1212

1313
import '../../codelessly_sdk.dart';
14-
import '../logging/error_handler.dart';
1514
import '../ui/codelessly_dialog_widget.dart';
1615

1716
/// Enum representing the types of API requests.

lib/src/transformers/widget_node_transformer_manager.dart

+23-9
Original file line numberDiff line numberDiff line change
@@ -118,21 +118,33 @@ abstract class WidgetNodeTransformerManager extends NodeTransformerManager<
118118
/// Convenience method to handle widget reactions.
119119
Widget wrapWithReaction(BuildContext context, BaseNode node, Widget widget) {
120120
if (node is! ReactionMixin) return widget;
121-
if (node is! BlendMixin) return widget;
122121
if (node case CanvasNode() || SpacerNode()) return widget;
123-
if (node is CustomPropertiesMixin && node is! IconNode) return widget;
124-
final InkWellModel? inkWell = node.inkWell;
122+
if (node is CustomPropertiesMixin &&
123+
node.handlesDefaultReactionsInternally) {
124+
// Node is a custom properties mixin and intends to handle reactions
125+
// internally, even default ones. So, we don't need to wrap it with
126+
// reactions.
127+
return widget;
128+
}
129+
final InkWellModel? inkWell = node is BlendMixin ? node.inkWell : null;
125130

131+
// Due to the way inkwell works internally, it is handled by
132+
// the individual node transformers internally if it is default shape mixin
133+
// because then it has fills that obscure the inkwell effect.
126134
if (node is DefaultShapeNode && inkWell != null) return widget;
127135

128136
final List<Reaction> onClickReactions = (node as ReactionMixin)
129137
.reactions
130-
.where((reaction) => reaction.trigger.type == TriggerType.click)
138+
.where((reaction) =>
139+
reaction.trigger.type == TriggerType.click &&
140+
reaction.action.enabled)
131141
.toList();
132142

133143
final List<Reaction> onLongPressReactions = (node as ReactionMixin)
134144
.reactions
135-
.where((reaction) => reaction.trigger.type == TriggerType.longPress)
145+
.where((reaction) =>
146+
reaction.trigger.type == TriggerType.longPress &&
147+
reaction.action.enabled)
136148
.toList();
137149

138150
if (inkWell != null) {
@@ -151,9 +163,8 @@ abstract class WidgetNodeTransformerManager extends NodeTransformerManager<
151163
),
152164
borderRadius: getBorderRadius(node),
153165
overlayColor: inkWell.overlayColor != null
154-
? MaterialStatePropertyAll<Color>(
155-
inkWell.overlayColor!.toFlutterColor(),
156-
)
166+
? WidgetStatePropertyAll<Color>(
167+
inkWell.overlayColor!.toFlutterColor())
157168
: null,
158169
splashColor: inkWell.splashColor?.toFlutterColor(),
159170
highlightColor: inkWell.highlightColor?.toFlutterColor(),
@@ -163,12 +174,15 @@ abstract class WidgetNodeTransformerManager extends NodeTransformerManager<
163174
),
164175
);
165176
} else {
166-
if ((node as ReactionMixin).reactions.isEmpty) {
177+
if (onClickReactions.isEmpty && onLongPressReactions.isEmpty) {
167178
return widget;
168179
}
180+
// TODO: should handle TriggerType.hover and TriggerType.unhover too.
169181
return MouseRegion(
170182
cursor: SystemMouseCursors.click,
183+
hitTestBehavior: HitTestBehavior.opaque,
171184
child: GestureDetector(
185+
behavior: HitTestBehavior.opaque,
172186
onTap: () => FunctionsRepository.triggerAction(
173187
context,
174188
TriggerType.click,

0 commit comments

Comments
 (0)