mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-19 00:26:18 +08:00
RTF slide dismiss
Closes #1135 Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import 'dart:math';
|
|
||||||
|
|
||||||
import 'package:PiliPlus/utils/storage_pref.dart';
|
import 'package:PiliPlus/utils/storage_pref.dart';
|
||||||
|
import 'package:flutter/gestures.dart' show PositionedGestureDetails;
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
|
||||||
@@ -15,6 +14,7 @@ abstract class CommonSlidePageState<T extends CommonSlidePage> extends State<T>
|
|||||||
Offset? downPos;
|
Offset? downPos;
|
||||||
bool? isSliding;
|
bool? isSliding;
|
||||||
|
|
||||||
|
late bool _isRTF = false;
|
||||||
late final bool enableSlide;
|
late final bool enableSlide;
|
||||||
AnimationController? _animController;
|
AnimationController? _animController;
|
||||||
Animation<Offset>? _anim;
|
Animation<Offset>? _anim;
|
||||||
@@ -62,9 +62,12 @@ abstract class CommonSlidePageState<T extends CommonSlidePage> extends State<T>
|
|||||||
builder: (_, constrains) {
|
builder: (_, constrains) {
|
||||||
final maxWidth = constrains.maxWidth;
|
final maxWidth = constrains.maxWidth;
|
||||||
|
|
||||||
void onDismiss() {
|
void onDismiss([_]) {
|
||||||
if (isSliding == true) {
|
if (isSliding == true) {
|
||||||
if (_animController!.value * maxWidth + downPos!.dx >= 100) {
|
final dx = downPos!.dx;
|
||||||
|
if (_animController!.value * maxWidth +
|
||||||
|
(_isRTF ? (maxWidth - dx) : dx) >=
|
||||||
|
100) {
|
||||||
Get.back();
|
Get.back();
|
||||||
} else {
|
} else {
|
||||||
_animController!.reverse();
|
_animController!.reverse();
|
||||||
@@ -74,7 +77,8 @@ abstract class CommonSlidePageState<T extends CommonSlidePage> extends State<T>
|
|||||||
isSliding = null;
|
isSliding = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
void onPan(Offset localPosition) {
|
void onPan(PositionedGestureDetails details) {
|
||||||
|
final localPosition = details.localPosition;
|
||||||
if (isSliding == false) {
|
if (isSliding == false) {
|
||||||
return;
|
return;
|
||||||
} else if (isSliding == null) {
|
} else if (isSliding == null) {
|
||||||
@@ -86,34 +90,32 @@ abstract class CommonSlidePageState<T extends CommonSlidePage> extends State<T>
|
|||||||
} else {
|
} else {
|
||||||
isSliding = false;
|
isSliding = false;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
isSliding = false;
|
||||||
}
|
}
|
||||||
} else if (isSliding == true) {
|
} else if (isSliding == true) {
|
||||||
if (localPosition.dx < 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_animController!.value =
|
_animController!.value =
|
||||||
max(0, (localPosition.dx - downPos!.dx)) / maxWidth;
|
(details.localPosition.dx - downPos!.dx).abs() / maxWidth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onPanDown: (details) {
|
onPanDown: (details) {
|
||||||
if (details.localPosition.dx > 30) {
|
final dx = details.localPosition.dx;
|
||||||
isSliding = false;
|
const offset = 30;
|
||||||
} else {
|
final isLTR = dx <= offset;
|
||||||
|
final isRTF = dx >= maxWidth - offset;
|
||||||
|
if (isLTR || isRTF) {
|
||||||
|
_isRTF = isRTF;
|
||||||
downPos = details.localPosition;
|
downPos = details.localPosition;
|
||||||
|
} else {
|
||||||
|
isSliding = false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onPanStart: (details) {
|
onPanStart: onPan,
|
||||||
onPan(details.localPosition);
|
onPanUpdate: onPan,
|
||||||
},
|
|
||||||
onPanUpdate: (details) {
|
|
||||||
onPan(details.localPosition);
|
|
||||||
},
|
|
||||||
onPanCancel: onDismiss,
|
onPanCancel: onDismiss,
|
||||||
onPanEnd: (_) {
|
onPanEnd: onDismiss,
|
||||||
onDismiss();
|
|
||||||
},
|
|
||||||
child: buildList(theme),
|
child: buildList(theme),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -692,7 +692,7 @@ List<SettingsModel> get extraSettings => [
|
|||||||
),
|
),
|
||||||
SettingsModel(
|
SettingsModel(
|
||||||
settingsType: SettingsType.sw1tch,
|
settingsType: SettingsType.sw1tch,
|
||||||
title: '侧滑关闭二级评论页面',
|
title: '侧滑关闭二级页面',
|
||||||
leading: Transform.rotate(
|
leading: Transform.rotate(
|
||||||
angle: pi * 1.5,
|
angle: pi * 1.5,
|
||||||
child: const Icon(Icons.touch_app),
|
child: const Icon(Icons.touch_app),
|
||||||
|
|||||||
Reference in New Issue
Block a user