Skip to content

Commit

Permalink
Add SmartMaskTriggerType (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
xdd666t committed Aug 6, 2022
1 parent 2d5d970 commit 3483867
Show file tree
Hide file tree
Showing 13 changed files with 118 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Add replaceBuilder (showAttach)
- Add onDismiss/onMask (showLoading)
- Add displayTime (show/showAttach/showLoading)
- Add SmartMaskTriggerType ([#71](https://github.com/fluttercandies/flutter_smart_dialog/issues/71))

# [4.3.x]

Expand Down
21 changes: 21 additions & 0 deletions lib/src/config/enum_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,24 @@ enum SmartAwaitOverType {
/// await 10毫秒后结束
none
}

/// The type of timing that is triggered when the mask is clicked
///
/// 点击遮罩时, 被触发时机的类型
enum SmartMaskTriggerType {
/// Triggered when the mask is clicked (down gesture)
///
/// 点击到遮罩时(down手势)触发
down,

/// Click to the mask, trigger when the move gesture (move gesture),
/// if the move event is not triggered, it will be downgraded to the up event trigger
///
/// 点击到遮罩, 移动手势时(move手势)触发, 如果move事件未触发, 将会降级到up事件触发
move,

/// Triggered when the mask is tapped and then raised (up gesture)
///
/// 点击到遮罩, 然后抬起手势时(up手势)触发
up
}
6 changes: 6 additions & 0 deletions lib/src/config/smart_config_attach.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class SmartConfigAttach {
this.backDismiss = true,
this.bindPage = true,
this.awaitOverType = SmartAwaitOverType.dialogDismiss,
this.maskTriggerType = SmartMaskTriggerType.up,
this.isExist = false,
});

Expand Down Expand Up @@ -123,6 +124,11 @@ class SmartConfigAttach {
/// 弹窗await结束的类型
final SmartAwaitOverType awaitOverType;

/// When the mask is clicked, the trigger timing type (please refer to the [SmartMaskTriggerType] note for details)
///
/// 点击遮罩时, 被触发时机的类型 (具体请查看[SmartMaskTriggerType]注释)
final SmartMaskTriggerType maskTriggerType;

/// whether attach dialog(showAttach()) exist on the screen
///
/// attach dialog(showAttach()),是否存在在界面上
Expand Down
6 changes: 6 additions & 0 deletions lib/src/config/smart_config_custom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class SmartConfigCustom {
this.backDismiss = true,
this.bindPage = true,
this.awaitOverType = SmartAwaitOverType.dialogDismiss,
this.maskTriggerType = SmartMaskTriggerType.up,
this.isExist = false,
});

Expand Down Expand Up @@ -123,6 +124,11 @@ class SmartConfigCustom {
/// 弹窗await结束的类型
final SmartAwaitOverType awaitOverType;

/// When the mask is clicked, the trigger timing type (please refer to the [SmartMaskTriggerType] note for details)
///
/// 点击遮罩时, 被触发时机的类型 (具体请查看[SmartMaskTriggerType]注释)
final SmartMaskTriggerType maskTriggerType;

/// whether custom dialog(show()) exist on the screen
///
/// 自定义dialog(show()),是否存在在界面上
Expand Down
6 changes: 6 additions & 0 deletions lib/src/config/smart_config_loading.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class SmartConfigLoading {
this.clickMaskDismiss = false,
this.leastLoadingTime = const Duration(milliseconds: 0),
this.awaitOverType = SmartAwaitOverType.dialogDismiss,
this.maskTriggerType = SmartMaskTriggerType.up,
this.isExist = false,
});

Expand Down Expand Up @@ -105,6 +106,11 @@ class SmartConfigLoading {
/// 弹窗await结束的类型
final SmartAwaitOverType awaitOverType;

/// When the mask is clicked, the trigger timing type (please refer to the [SmartMaskTriggerType] note for details)
///
/// 点击遮罩时, 被触发时机的类型 (具体请查看[SmartMaskTriggerType]注释)
final SmartMaskTriggerType maskTriggerType;

/// whether loading(showLoading()) exist on the screen
///
/// loading(showLoading())是否存在在界面上
Expand Down
6 changes: 6 additions & 0 deletions lib/src/config/smart_config_toast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class SmartConfigToast {
this.displayTime = const Duration(milliseconds: 2000),
this.intervalTime = const Duration(milliseconds: 100),
this.awaitOverType = SmartAwaitOverType.dialogDismiss,
this.maskTriggerType = SmartMaskTriggerType.up,
this.isExist = false,
});

Expand Down Expand Up @@ -129,6 +130,11 @@ class SmartConfigToast {
/// 弹窗await结束的类型
final SmartAwaitOverType awaitOverType;

/// When the mask is clicked, the trigger timing type (please refer to the [SmartMaskTriggerType] note for details)
///
/// 点击遮罩时, 被触发时机的类型 (具体请查看[SmartMaskTriggerType]注释)
final SmartMaskTriggerType maskTriggerType;

/// whether toast(showToast()) exist on the screen
///
/// toast(showToast())是否存在在界面上
Expand Down
2 changes: 2 additions & 0 deletions lib/src/custom/custom_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class CustomDialog extends BaseDialog {
useSystem: useSystem,
reuse: true,
awaitOverType: SmartDialog.config.custom.awaitOverType,
maskTriggerType: SmartDialog.config.custom.maskTriggerType,
onMask: () {
onMask?.call();
if (!clickMaskDismiss || !_clickMaskDebounce() || permanent) return;
Expand Down Expand Up @@ -139,6 +140,7 @@ class CustomDialog extends BaseDialog {
onDismiss: _handleDismiss(onDismiss, displayTime),
useSystem: useSystem,
awaitOverType: SmartDialog.config.attach.awaitOverType,
maskTriggerType: SmartDialog.config.attach.maskTriggerType,
onMask: () {
onMask?.call();
if (!clickMaskDismiss || !_clickMaskDebounce() || permanent) return;
Expand Down
1 change: 1 addition & 0 deletions lib/src/custom/custom_loading.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class CustomLoading extends BaseDialog {
useSystem: false,
reuse: true,
awaitOverType: SmartDialog.config.loading.awaitOverType,
maskTriggerType: SmartDialog.config.loading.maskTriggerType,
onMask: () {
onMask?.call();
if (!clickMaskDismiss) return;
Expand Down
1 change: 1 addition & 0 deletions lib/src/custom/custom_toast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class CustomToast extends BaseDialog {
useSystem: false,
reuse: false,
awaitOverType: SmartDialog.config.toast.awaitOverType,
maskTriggerType: SmartDialog.config.toast.maskTriggerType,
onMask: () => clickMaskDismiss ? _realDismiss() : null,
);
}
Expand Down
4 changes: 4 additions & 0 deletions lib/src/custom/main_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class MainDialog {
required bool useSystem,
required bool reuse,
required SmartAwaitOverType awaitOverType,
required SmartMaskTriggerType maskTriggerType,
}) {
//custom dialog
_widget = SmartDialogWidget(
Expand All @@ -54,6 +55,7 @@ class MainDialog {
maskWidget: maskWidget,
child: widget,
onMask: onMask,
maskTriggerType: maskTriggerType,
);

_handleCommonOperate(
Expand Down Expand Up @@ -86,6 +88,7 @@ class MainDialog {
required VoidCallback? onDismiss,
required bool useSystem,
required SmartAwaitOverType awaitOverType,
required SmartMaskTriggerType maskTriggerType,
}) {
//attach dialog
_widget = AttachDialogWidget(
Expand All @@ -105,6 +108,7 @@ class MainDialog {
highlightBuilder: highlightBuilder,
child: widget,
onMask: onMask,
maskTriggerType: maskTriggerType,
);

_handleCommonOperate(
Expand Down
35 changes: 32 additions & 3 deletions lib/src/widget/attach_dialog_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class AttachDialogWidget extends StatefulWidget {
required this.maskColor,
required this.highlightBuilder,
required this.maskWidget,
required this.maskTriggerType,
}) : super(key: key);

///target context
Expand Down Expand Up @@ -90,6 +91,9 @@ class AttachDialogWidget extends StatefulWidget {
/// 溶解遮罩,设置高亮位置
final HighlightBuilder highlightBuilder;

/// 遮罩点击时, 被触发的时机
final SmartMaskTriggerType maskTriggerType;

@override
_AttachDialogWidgetState createState() => _AttachDialogWidgetState();
}
Expand All @@ -112,6 +116,8 @@ class _AttachDialogWidgetState extends State<AttachDialogWidget>

late Widget _child;

bool _maskTrigger = false;

@override
void initState() {
_child = widget.child;
Expand Down Expand Up @@ -207,7 +213,7 @@ class _AttachDialogWidgetState extends State<AttachDialogWidget>

return Stack(children: [
//暗色背景widget动画
_buildBgAnimation(onPointerUp: widget.onMask, child: maskWidget),
_buildBgAnimation(onMask: widget.onMask, child: maskWidget),

//内容Widget动画
Positioned(
Expand All @@ -221,14 +227,37 @@ class _AttachDialogWidgetState extends State<AttachDialogWidget>
}

Widget _buildBgAnimation({
required void Function()? onPointerUp,
required void Function()? onMask,
required Widget? child,
}) {
Function()? onPointerDown;
Function()? onPointerMove;
Function()? onPointerUp;
if (widget.maskTriggerType == SmartMaskTriggerType.down) {
onPointerDown = onMask;
} else if (widget.maskTriggerType == SmartMaskTriggerType.move) {
onPointerMove = onMask;
} else {
onPointerUp = onMask;
}

return FadeTransition(
opacity: CurvedAnimation(parent: _ctrlBg!, curve: Curves.linear),
child: Listener(
behavior: HitTestBehavior.translucent,
onPointerUp: (event) => onPointerUp?.call(),
onPointerDown: (event) {
onPointerDown?.call();
if (onPointerDown != null) _maskTrigger = true;
},
onPointerMove: (event) {
if (!_maskTrigger) onPointerMove?.call();
if (onPointerMove != null) _maskTrigger = true;
},
onPointerUp: (event) {
onPointerUp?.call();
if (onPointerUp == null && !_maskTrigger) onMask?.call();
_maskTrigger = false;
},
child: child,
),
);
Expand Down
34 changes: 31 additions & 3 deletions lib/src/widget/smart_dialog_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class SmartDialogWidget extends StatefulWidget {
required this.animationType,
required this.maskColor,
required this.maskWidget,
required this.maskTriggerType,
}) : super(key: key);

/// 内容widget
Expand Down Expand Up @@ -51,6 +52,9 @@ class SmartDialogWidget extends StatefulWidget {
/// 自定义遮罩Widget
final Widget? maskWidget;

/// 遮罩点击时, 被触发的时机
final SmartMaskTriggerType maskTriggerType;

@override
_SmartDialogWidgetState createState() => _SmartDialogWidgetState();
}
Expand All @@ -60,6 +64,7 @@ class _SmartDialogWidgetState extends State<SmartDialogWidget>
AnimationController? _ctrlBg;
late AnimationController _ctrlBody;
Offset? _offset;
bool _maskTrigger = false;

@override
void initState() {
Expand Down Expand Up @@ -100,7 +105,7 @@ class _SmartDialogWidgetState extends State<SmartDialogWidget>
return Stack(children: [
//暗色背景widget动画
_buildBgAnimation(
onPointerUp: widget.onMask,
onMask: widget.onMask,
child: (widget.maskWidget != null && !widget.usePenetrate)
? widget.maskWidget
: Container(color: widget.usePenetrate ? null : widget.maskColor),
Expand All @@ -115,14 +120,37 @@ class _SmartDialogWidgetState extends State<SmartDialogWidget>
}

Widget _buildBgAnimation({
required void Function()? onPointerUp,
required void Function()? onMask,
required Widget? child,
}) {
Function()? onPointerDown;
Function()? onPointerMove;
Function()? onPointerUp;
if (widget.maskTriggerType == SmartMaskTriggerType.down) {
onPointerDown = onMask;
} else if (widget.maskTriggerType == SmartMaskTriggerType.move) {
onPointerMove = onMask;
} else {
onPointerUp = onMask;
}

return FadeTransition(
opacity: CurvedAnimation(parent: _ctrlBg!, curve: Curves.linear),
child: Listener(
behavior: HitTestBehavior.translucent,
onPointerUp: (event) => onPointerUp?.call(),
onPointerDown: (event) {
onPointerDown?.call();
if (onPointerDown != null) _maskTrigger = true;
},
onPointerMove: (event) {
if (!_maskTrigger) onPointerMove?.call();
if (onPointerMove != null) _maskTrigger = true;
},
onPointerUp: (event) {
onPointerUp?.call();
if (onPointerUp == null && !_maskTrigger) onMask?.call();
_maskTrigger = false;
},
child: child,
),
);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description:
An elegant Flutter Dialog solution,
Easily implement Toast, Loading and custom Dialog,
Make the use of the dialog easier!
version: 4.5.3+8
version: 4.5.4
homepage: https://github.com/fluttercandies/flutter_smart_dialog
# flutter pub publish --server=https://pub.dartlang.org

Expand Down

0 comments on commit 3483867

Please sign in to comment.