Skip to content

Commit

Permalink
Update: Migrate to Flutter 3.10 and update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
AmosHuKe committed Feb 8, 2024
1 parent 58524c4 commit 48a4769
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 150 deletions.
8 changes: 5 additions & 3 deletions lib/src/config/tilt_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -339,14 +339,16 @@ class TiltDirection {

/// 验证合法的方向并返回方向数据
///
/// * [tiltDirection] 需要验证的方向坐标
/// * [validator] 验证的方向范围
/// - [tiltDirection] 需要验证的方向坐标
/// - [validator] 验证的方向范围
///
/// @return [TiltDirection]
static TiltDirection validator(
TiltDirection tiltDirection,
List<TiltDirection> validator,
) {
final double x = tiltDirection.dx, y = tiltDirection.dy;
late double dx = 0.0, dy = 0.0;
double dx = 0.0, dy = 0.0;

for (final TiltDirection value in validator) {
/// 默认最大设置的验证范围,避免方向值超出验证值的时候会返回 0
Expand Down
152 changes: 45 additions & 107 deletions lib/src/internal/tilt_decoration_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ mixin TiltDecoration {
///
/// 范围:0-1
///
/// * [width], [height] 区域尺寸
/// * [areaProgress] 当前坐标的区域进度
/// * [direction] 方向计算方式
/// * [LightDirection] 光线方向
/// * [ShadowDirection] 阴影方向
/// - [areaProgress] 当前坐标的区域进度
/// - [direction] 方向计算方式
/// - [LightDirection] 光线方向
/// - [ShadowDirection] 阴影方向
///
/// 可选项
/// * [min] 最小进度限制 0-1
/// * [max] 最大进度限制 0-1
/// * [enableReverse] 开启反向
/// - [min] 最小进度限制 0-1
/// - [max] 最大进度限制 0-1
/// - [enableReverse] 开启反向
///
/// @return [double] 方向进度 0-1
double tiltDecorationDirectionProgress<T>(
Offset areaProgress,
T direction, {
Expand All @@ -32,121 +32,59 @@ mixin TiltDecoration {
final Offset progress = -areaProgress;
final double progressX = progress.dx, progressY = progress.dy;

/// 区域进度
late double dataX = progressX, dataY = progressY;

/// 距离中心
final double dataDistance = Utils.p2pDistance(
Offset.zero,
Offset(dataX, dataY),
Offset(progressX, progressY),
);

/// 限制距离中心
final double constraintsDistance = dataDistance > max ? max : dataDistance;

/// 区域进度
double dataX = progressX, dataY = progressY;

/// 进度
late double progressData = min;
double progressData = min;

/// 光源方向计算方式
if (direction.runtimeType == LightDirection) {
switch (direction as LightDirection) {
case LightDirection.none:
break;
case LightDirection.around:
final double distance = constraintsDistance;
progressData = distance;
break;
case LightDirection.all:
progressData = max;
break;
case LightDirection.top:
progressData = progressY;
break;
case LightDirection.bottom:
progressData = -progressY;
break;
case LightDirection.left:
progressData = progressX;
break;
case LightDirection.right:
progressData = -progressX;
break;
case LightDirection.center:
final double distance = constraintsDistance;
progressData = max - distance;
break;
case LightDirection.topLeft:
progressData = progressX + progressY;
break;
case LightDirection.bottomRight:
progressData = -(progressX + progressY);
break;
case LightDirection.topRight:
progressData = -(progressX - progressY);
break;
case LightDirection.bottomLeft:
progressData = progressX - progressY;
break;
case LightDirection.xCenter:
if (progressY < 0.0) dataY = -progressY;
progressData = max - dataY;
break;
case LightDirection.yCenter:
if (progressX < 0.0) dataX = -progressX;
progressData = max - dataX;
break;
}
progressData = switch (direction as LightDirection) {
LightDirection.none => progressData,
LightDirection.around => constraintsDistance,
LightDirection.all => max,
LightDirection.top => progressY,
LightDirection.bottom => -progressY,
LightDirection.left => progressX,
LightDirection.right => -progressX,
LightDirection.center => max - constraintsDistance,
LightDirection.topLeft => progressX + progressY,
LightDirection.bottomRight => -(progressX + progressY),
LightDirection.topRight => -(progressX - progressY),
LightDirection.bottomLeft => progressX - progressY,
LightDirection.xCenter => max - (progressY < 0.0 ? -progressY : dataY),
LightDirection.yCenter => max - (progressX < 0.0 ? -progressX : dataX),
};
}

/// 阴影方向计算方式
if (direction.runtimeType == ShadowDirection) {
switch (direction as ShadowDirection) {
case ShadowDirection.none:
break;
case ShadowDirection.around:
final double distance = constraintsDistance;
progressData = distance;
break;
case ShadowDirection.all:
progressData = max;
break;
case ShadowDirection.top:
progressData = -progressY;
break;
case ShadowDirection.bottom:
progressData = progressY;
break;
case ShadowDirection.left:
progressData = -progressX;
break;
case ShadowDirection.right:
progressData = progressX;
break;
case ShadowDirection.center:
final double distance = constraintsDistance;
progressData = max - distance;
break;
case ShadowDirection.topLeft:
progressData = -(progressX + progressY);
break;
case ShadowDirection.bottomRight:
progressData = progressX + progressY;
break;
case ShadowDirection.topRight:
progressData = progressX - progressY;
break;
case ShadowDirection.bottomLeft:
progressData = -(progressX - progressY);
break;
case ShadowDirection.xCenter:
if (progressY < 0.0) dataY = -progressY;
progressData = max - dataY;
break;
case ShadowDirection.yCenter:
if (progressX < 0.0) dataX = -progressX;
progressData = max - dataX;
break;
}
progressData = switch (direction as ShadowDirection) {
ShadowDirection.none => progressData,
ShadowDirection.around => constraintsDistance,
ShadowDirection.all => max,
ShadowDirection.top => -progressY,
ShadowDirection.bottom => progressY,
ShadowDirection.left => -progressX,
ShadowDirection.right => progressX,
ShadowDirection.center => max - constraintsDistance,
ShadowDirection.topLeft => -(progressX + progressY),
ShadowDirection.bottomRight => progressX + progressY,
ShadowDirection.topRight => progressX - progressY,
ShadowDirection.bottomLeft => -(progressX - progressY),
ShadowDirection.xCenter => max - (progressY < 0.0 ? -progressY : dataY),
ShadowDirection.yCenter => max - (progressX < 0.0 ? -progressX : dataX),
};
}

/// 强度
Expand Down
6 changes: 6 additions & 0 deletions lib/src/internal/tilt_tween_animation_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ mixin TiltTweenAnimation {
/// - [isMove] 是否移动
/// - [tiltConfig] TiltConfig
/// - [areaProgress] 当前进度
///
/// @return [Offset] 倾斜反向进度
Offset tiltTweenAnimationEnd(
bool isMove,
TiltConfig tiltConfig,
Expand All @@ -23,6 +25,8 @@ mixin TiltTweenAnimation {
/// - [isMove] 是否移动
/// - [currentGesturesType] 当前手势类型
/// - [tiltConfig] TiltConfig
///
/// @return [Duration]
Duration tiltTweenAnimationDuration(
bool isMove,
GesturesType currentGesturesType,
Expand All @@ -42,6 +46,8 @@ mixin TiltTweenAnimation {
/// - [isMove] 是否移动
/// - [currentGesturesType] 当前手势类型
/// - [tiltConfig] TiltConfig
///
/// @return [Curve]
Curve tiltTweenAnimationCurve(
bool isMove,
GesturesType currentGesturesType,
Expand Down
Loading

0 comments on commit 48a4769

Please sign in to comment.