Skip to content

Commit

Permalink
Miscellaneous improvements
Browse files Browse the repository at this point in the history
- Allow external components to have reactions.
- Introduce handlesDefaultReactionsInternally to better handle external reactivity for nodes with custom properties.
  • Loading branch information
BirjuVachhani committed Jul 1, 2024
1 parent 689ab2f commit 1119197
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
8 changes: 7 additions & 1 deletion lib/src/api/mixins.dart
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,13 @@ mixin CornerMixin on BaseNode {
}

/// Indicates that the node has some custom properties.
mixin CustomPropertiesMixin on BaseNode {}
mixin CustomPropertiesMixin on BaseNode {
/// Whether the node with custom properties handles its default reactions
/// like click, long press, etc. internally. If this is true then the
/// node itself is responsible for handling its own reactions. Otherwise,
/// the transformer will provide for the default reactions.
bool get handlesDefaultReactionsInternally => true;
}

/// Defines node that preserves its aspect ratio and cannot be resized by only
/// its width or height.
Expand Down
13 changes: 12 additions & 1 deletion lib/src/api/nodes/external_component_node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ part 'external_component_node.g.dart';
/// An inert node that does nothing.
/// This is populated dynamically through the Codelessly SDK.
@JsonSerializable()
class ExternalComponentNode extends BaseNode with CustomPropertiesMixin {
class ExternalComponentNode extends SceneNode with CustomPropertiesMixin {
@override
final String type = 'external';

Expand All @@ -20,6 +20,9 @@ class ExternalComponentNode extends BaseNode with CustomPropertiesMixin {
/// nodes to the same widget builder.
String? builderID;

@override
bool get handlesDefaultReactionsInternally => false;

/// Creates an [ExternalComponentNode] with the given data.
ExternalComponentNode({
required super.id,
Expand All @@ -40,12 +43,20 @@ class ExternalComponentNode extends BaseNode with CustomPropertiesMixin {
super.edgePins,
super.aspectRatioLock,
super.positioningMode,
super.parentID,
super.reactions,
super.variables,
super.multipleVariables,
});

/// Creates a [ExternalComponentNode] from a JSON object.
factory ExternalComponentNode.fromJson(Map json) =>
_$ExternalComponentNodeFromJson(json);

@override
List<TriggerType> get triggerTypes =>
[TriggerType.click, TriggerType.longPress];

@override
Map toJson() => _$ExternalComponentNodeToJson(this);
}
16 changes: 11 additions & 5 deletions lib/src/api/nodes/external_component_node.g.dart

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

0 comments on commit 1119197

Please sign in to comment.