Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/conceptadev/mix
Browse files Browse the repository at this point in the history
  • Loading branch information
leoafarias committed Mar 25, 2024
2 parents d33cd22 + 0a66a5b commit 8c4bf00
Show file tree
Hide file tree
Showing 48 changed files with 1,132 additions and 682 deletions.
3 changes: 1 addition & 2 deletions lib/mix.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export 'src/decorators/fractionally_sized_box_widget_decorator.dart';
export 'src/decorators/intrinsic_widget_decorator.dart';
export 'src/decorators/opacity_widget_decorator.dart';
export 'src/decorators/rotated_box_widget_decorator.dart';
export 'src/decorators/scale_widget_decorator.dart';
export 'src/decorators/sized_box_widget_decorator.dart';
export 'src/decorators/transform_widget_decorator.dart';
export 'src/decorators/visibility_widget_decorator.dart';
Expand Down Expand Up @@ -107,6 +106,6 @@ export 'src/utils/custom_focusable_action_detector.dart';
export 'src/utils/helper_util.dart';
export 'src/utils/style_recipe.dart';
export 'src/variants/variant.dart';
export 'src/widgets/pressable/pressable_data.notifier.dart';
export 'src/widgets/pressable/pressable_state.dart';
export 'src/widgets/pressable/pressable_util.dart';
export 'src/widgets/pressable/pressable_widget.dart';
53 changes: 29 additions & 24 deletions lib/src/attributes/variant_attribute.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,42 @@ import '../factory/style_mix.dart';
import '../variants/variant.dart';

@immutable
class VariantAttribute<T extends Variant> extends Attribute
with Mergeable<VariantAttribute<T>> {
final T variant;
abstract class StyleVariantAttribute<V extends StyleVariant> extends Attribute
with Mergeable<StyleVariantAttribute<V>> {
final V variant;
final Style _style;

const VariantAttribute(this.variant, Style style) : _style = style;
const StyleVariantAttribute(this.variant, Style style) : _style = style;

Style get value => _style;

bool matches(Iterable<Variant> otherVariants) =>
otherVariants.contains(variant);
bool matches(Iterable<StyleVariant> otherVariants) =>
variant.matches(otherVariants);

@override
VariantAttribute<T> merge(VariantAttribute<T> other) {
if (other.variant != variant) throw throwArgumentError(other);

return VariantAttribute(variant, _style.merge(other._style));
}
get props => [variant, _style];

@override
Object get type => ObjectKey(variant);
}

@immutable
class VariantAttribute extends StyleVariantAttribute<Variant> {
const VariantAttribute(super.variant, super.style);

@override
get props => [variant, value];
VariantAttribute merge(VariantAttribute other) {
if (other.variant != variant) throw throwArgumentError(other);

return VariantAttribute(variant, _style.merge(other._style));
}
}

mixin WhenVariant<T extends Variant> on VariantAttribute<T> {
mixin WhenVariant<T extends StyleVariant> on StyleVariantAttribute<T> {
bool when(BuildContext context);
}

@immutable
class ContextVariantAttribute extends VariantAttribute<ContextVariant>
class ContextVariantAttribute extends StyleVariantAttribute<ContextVariant>
with WhenVariant<ContextVariant> {
const ContextVariantAttribute(super.variant, super.style);

Expand All @@ -51,7 +55,7 @@ class ContextVariantAttribute extends VariantAttribute<ContextVariant>
}
}

ArgumentError throwArgumentError<T extends VariantAttribute>(T other) {
ArgumentError throwArgumentError<T extends StyleVariantAttribute>(T other) {
throw ArgumentError.value(
other.runtimeType,
'other',
Expand All @@ -60,26 +64,27 @@ ArgumentError throwArgumentError<T extends VariantAttribute>(T other) {
}

@immutable
class MultiVariantAttribute extends VariantAttribute<MultiVariant>
class MultiVariantAttribute extends StyleVariantAttribute<MultiVariant>
with WhenVariant<MultiVariant> {
const MultiVariantAttribute(super.variant, super.style);

// Remove all variants in given a list
VariantAttribute remove(Iterable<Variant> variantsToRemove) {
StyleVariantAttribute remove(Iterable<StyleVariant> variantsToRemove) {
final variant = this.variant.remove(variantsToRemove);
if (variant is MultiVariant) {
return MultiVariantAttribute(variant, _style);
} else if (variant is ContextVariant) {
return ContextVariantAttribute(variant, _style);
} else if (variant is Variant) {
return VariantAttribute(variant, _style);
}

return VariantAttribute(variant, _style);
throw ArgumentError.value(
variant,
'variant',
'Variant must be a Variant, ContextVariant, or MultiVariant',
);
}

@override
bool matches(Iterable<Variant> otherVariants) =>
variant.matches(otherVariants);

@override
bool when(BuildContext context) => variant.when(context);

Expand Down
11 changes: 11 additions & 0 deletions lib/src/core/attribute.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,14 @@ abstract class Spec<T extends Spec<T>> with Comparable {
/// Linearly interpolate with another [Spec] object.
T lerp(covariant T? other, double t);
}

@immutable
abstract class StyleAttributeBuilder<Self extends StyleAttributeBuilder<Self>>
extends StyleAttribute {
const StyleAttributeBuilder();

Attribute? builder(BuildContext context);

@override
Type get type => Self;
}
6 changes: 3 additions & 3 deletions lib/src/core/styled_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ abstract class StyledWidget extends StatelessWidget {
}

Widget applyDecorators(MixData mix, Widget child) {
return mix.animation.isAnimated
return mix.isAnimated
? RenderAnimatedDecorators(
mix: mix,
orderOfDecorators: orderOfDecorators,
duration: mix.animation.duration,
curve: mix.animation.curve,
duration: mix.animation!.duration,
curve: mix.animation!.curve,
child: child,
)
: RenderDecorators(
Expand Down
58 changes: 0 additions & 58 deletions lib/src/decorators/scale_widget_decorator.dart

This file was deleted.

64 changes: 55 additions & 9 deletions lib/src/decorators/transform_widget_decorator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import '../factory/mix_provider_data.dart';

class TransformDecoratorSpec extends DecoratorSpec<TransformDecoratorSpec> {
final Matrix4? transform;
const TransformDecoratorSpec({this.transform});
final Alignment? alignment;

const TransformDecoratorSpec({this.transform, this.alignment});

@override
TransformDecoratorSpec lerp(TransformDecoratorSpec? other, double t) {
Expand All @@ -19,43 +21,87 @@ class TransformDecoratorSpec extends DecoratorSpec<TransformDecoratorSpec> {
}

@override
TransformDecoratorSpec copyWith({Matrix4? transform}) {
return TransformDecoratorSpec(transform: transform ?? this.transform);
TransformDecoratorSpec copyWith({
Matrix4? transform,
Alignment? alignment,
}) {
return TransformDecoratorSpec(
transform: transform ?? this.transform,
alignment: alignment ?? this.alignment,
);
}

@override
List<Object?> get props => [transform];
List<Object?> get props => [transform, alignment];

@override
Widget build(Widget child) {
return Transform(transform: transform ?? Matrix4.identity(), child: child);
return Transform(
transform: transform ?? Matrix4.identity(),
alignment: alignment ?? Alignment.center,
child: child,
);
}
}

class TransformDecoratorAttribute extends DecoratorAttribute<
TransformDecoratorAttribute, TransformDecoratorSpec> {
final Matrix4? transform;
const TransformDecoratorAttribute({this.transform});
final Alignment? alignment;

const TransformDecoratorAttribute({this.transform, this.alignment});

@override
TransformDecoratorAttribute merge(TransformDecoratorAttribute? other) {
return TransformDecoratorAttribute(
transform: other?.transform ?? transform,
transform:
other?.transform?.multiplied(transform ?? Matrix4.identity()) ??
transform,
alignment: other?.alignment ?? alignment,
);
}

@override
TransformDecoratorSpec resolve(MixData mix) {
return TransformDecoratorSpec(transform: transform);
return TransformDecoratorSpec(
transform: transform,
alignment: alignment,
);
}

@override
List<Object?> get props => [transform];
List<Object?> get props => [transform, alignment];
}

class TransformUtility<T extends StyleAttribute>
extends MixUtility<T, TransformDecoratorAttribute> {
const TransformUtility(super.builder);

T call(Matrix4 value) =>
builder(TransformDecoratorAttribute(transform: value));

T scale(double value) => builder(
TransformDecoratorAttribute(
transform: Matrix4.diagonal3Values(value, value, 1.0),
alignment: Alignment.center,
),
);

T rotate(double value) => builder(
TransformDecoratorAttribute(
transform: Matrix4.rotationZ(value),
alignment: Alignment.center,
),
);

T flip(bool x, bool y) => builder(
TransformDecoratorAttribute(
transform: Matrix4.diagonal3Values(
x ? -1.0 : 1.0,
y ? -1.0 : 1.0,
1.0,
),
alignment: Alignment.center,
),
);
}
6 changes: 0 additions & 6 deletions lib/src/decorators/widget_decorator_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import 'clip_widget_decorator.dart';
import 'fractionally_sized_box_widget_decorator.dart';
import 'intrinsic_widget_decorator.dart';
import 'opacity_widget_decorator.dart';
import 'scale_widget_decorator.dart';
import 'sized_box_widget_decorator.dart';
import 'transform_widget_decorator.dart';
import 'visibility_widget_decorator.dart';
Expand Down Expand Up @@ -51,11 +50,6 @@ const _defaultOrder = [
// which is critical for preserving the visual integrity of images and other aspect-sensitive content.
AspectRatioDecoratorAttribute,

// 8. ScaleDecorator: Scales the widget according to a given scale factor. This decorator is applied after
// the aspect ratio is considered to ensure the widget scales uniformly, affecting its overall size and maintaining
// the aspect ratio integrity.
ScaleDecoratorAttribute,

// 9. TransformDecorator: Applies arbitrary transformations, such as rotation, scaling, and translation.
// Transformations are applied after all sizing and positioning adjustments to modify the widget's appearance
// and position in more complex ways without altering the logical layout.
Expand Down
4 changes: 2 additions & 2 deletions lib/src/decorators/widget_decorators_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'fractionally_sized_box_widget_decorator.dart';
import 'intrinsic_widget_decorator.dart';
import 'opacity_widget_decorator.dart';
import 'rotated_box_widget_decorator.dart';
import 'scale_widget_decorator.dart';
import 'sized_box_widget_decorator.dart';
import 'transform_widget_decorator.dart';
import 'visibility_widget_decorator.dart';
Expand All @@ -16,7 +15,8 @@ T selfBuilder<T extends StyleAttribute>(T decorator) => decorator;

const intrinsicWidth = IntrinsicWidthWidgetUtility(selfBuilder);
const intrinsicHeight = IntrinsicHeightWidgetUtility(selfBuilder);
const scale = ScaleUtility(selfBuilder);
final scale = transform.scale;
final flip = transform.flip;
const opacity = OpacityUtility(selfBuilder);
const rotate = RotatedBoxWidgetUtility(selfBuilder);

Expand Down
10 changes: 2 additions & 8 deletions lib/src/deprecations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,10 @@ final large = onLarge;
final hover = onHover;

@Deprecated('Use onFocused instead')
final focus = onFocused;
const focus = onFocused;

@Deprecated('Use onFocused instead')
final onFocus = onFocused;
const onFocus = onFocused;

@Deprecated('Use onPortrait instead')
final portrait = onPortrait;
Expand Down Expand Up @@ -548,13 +548,7 @@ final textBaseline = text.style.textBaseline;
@Deprecated('Use borderRadius.circular instead')
final squared = borderRadius.zero;

// linearGradient
@Deprecated('Use box.decoration.gradient.linear instead')
final linearGradient = box.decoration.gradient.linear;

// radialGradient
@Deprecated('Use box.decoration.gradient.radial instead')
final radialGradient = box.decoration.gradient.radial;

// flexDirection
@Deprecated('Use flexDirection instead')
Expand Down
Loading

0 comments on commit 8c4bf00

Please sign in to comment.