mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
feat: custom spring (#304)
This commit is contained in:
committed by
GitHub
parent
6506afa732
commit
b2c520bd91
@@ -14,6 +14,7 @@ import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
|
||||
|
||||
import '../../utils/storage.dart';
|
||||
import '../../utils/utils.dart';
|
||||
import 'package:PiliPlus/common/widgets/spring_physics.dart';
|
||||
|
||||
class ListSheetContent extends StatefulWidget {
|
||||
const ListSheetContent({
|
||||
@@ -423,6 +424,7 @@ class _ListSheetContentState extends State<ListSheetContent>
|
||||
? Material(
|
||||
color: Colors.transparent,
|
||||
child: TabBarView(
|
||||
physics: customTabBarViewScrollPhysics,
|
||||
controller: _ctr,
|
||||
children: List.generate(
|
||||
widget.season.sections.length,
|
||||
|
||||
20
lib/common/widgets/spring_physics.dart
Normal file
20
lib/common/widgets/spring_physics.dart
Normal file
@@ -0,0 +1,20 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
|
||||
class CustomTabBarViewScrollPhysics extends ScrollPhysics {
|
||||
CustomTabBarViewScrollPhysics({super.parent});
|
||||
|
||||
@override
|
||||
CustomTabBarViewScrollPhysics applyTo(ScrollPhysics? ancestor) {
|
||||
return CustomTabBarViewScrollPhysics(parent: buildParent(ancestor)!);
|
||||
}
|
||||
|
||||
@override
|
||||
SpringDescription spring = SpringDescription(
|
||||
mass: GStorage.springDescription[0],
|
||||
stiffness: GStorage.springDescription[1],
|
||||
damping: GStorage.springDescription[2]
|
||||
);
|
||||
}
|
||||
|
||||
final customTabBarViewScrollPhysics = CustomTabBarViewScrollPhysics();
|
||||
@@ -16,6 +16,7 @@ import 'package:PiliPlus/pages/main/index.dart';
|
||||
import '../../utils/grid.dart';
|
||||
import 'controller.dart';
|
||||
import 'widgets/bangumi_card_v.dart';
|
||||
import 'package:PiliPlus/common/widgets/spring_physics.dart';
|
||||
|
||||
class BangumiPage extends StatefulWidget {
|
||||
const BangumiPage({
|
||||
@@ -162,6 +163,7 @@ class _BangumiPageState extends State<BangumiPage>
|
||||
.toList()),
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
physics: customTabBarViewScrollPhysics,
|
||||
children: types
|
||||
.map((type) =>
|
||||
PgcIndexPage(indexType: type))
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'package:PiliPlus/utils/storage.dart';
|
||||
import '../../http/danmaku_block.dart';
|
||||
import '../../models/user/danmaku_block.dart';
|
||||
import '../../plugin/pl_player/controller.dart';
|
||||
import 'package:PiliPlus/common/widgets/spring_physics.dart';
|
||||
|
||||
class DanmakuBlockPage extends StatefulWidget {
|
||||
const DanmakuBlockPage({super.key});
|
||||
@@ -142,6 +143,7 @@ class _DanmakuBlockPageState extends State<DanmakuBlockPage> {
|
||||
]),
|
||||
),
|
||||
body: TabBarView(
|
||||
physics: customTabBarViewScrollPhysics,
|
||||
controller: _danmakuBlockController.tabController,
|
||||
children: [
|
||||
for (var i = 0; i < ruleLabels.length; i++)
|
||||
|
||||
@@ -11,6 +11,7 @@ import 'package:material_design_icons_flutter/material_design_icons_flutter.dart
|
||||
|
||||
import 'controller.dart';
|
||||
import 'widgets/up_panel.dart';
|
||||
import 'package:PiliPlus/common/widgets/spring_physics.dart';
|
||||
|
||||
enum ReplyOption { allow, close, choose }
|
||||
|
||||
@@ -183,7 +184,7 @@ class _DynamicsPageState extends State<DynamicsPage>
|
||||
if (upPanelPosition == UpPanelPosition.leftFixed) upPanelPart(),
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
physics: customTabBarViewScrollPhysics,
|
||||
controller: _dynamicsController.tabController,
|
||||
children: _dynamicsController.tabsPageList,
|
||||
)),
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import '../../common/widgets/network_img_layer.dart';
|
||||
import 'controller.dart';
|
||||
import 'package:PiliPlus/common/widgets/spring_physics.dart';
|
||||
|
||||
class EmotePanel extends StatefulWidget {
|
||||
final Function onChoose;
|
||||
@@ -36,6 +37,7 @@ class _EmotePanelState extends State<EmotePanel>
|
||||
children: [
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
physics: customTabBarViewScrollPhysics,
|
||||
controller: _emotePanelController.tabController,
|
||||
children: (loadingState.response as List<Packages>).map(
|
||||
(e) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:get/get.dart';
|
||||
import 'controller.dart';
|
||||
import 'widgets/follow_list.dart';
|
||||
import 'widgets/owner_follow_list.dart';
|
||||
import 'package:PiliPlus/common/widgets/spring_physics.dart';
|
||||
|
||||
class FollowPage extends StatefulWidget {
|
||||
const FollowPage({super.key});
|
||||
@@ -83,6 +84,7 @@ class _FollowPageState extends State<FollowPage> {
|
||||
]),
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
physics: customTabBarViewScrollPhysics,
|
||||
controller: _followController.tabController,
|
||||
children: [
|
||||
for (var i = 0;
|
||||
|
||||
@@ -10,6 +10,7 @@ import 'package:PiliPlus/common/widgets/network_img_layer.dart';
|
||||
import 'package:PiliPlus/utils/feed_back.dart';
|
||||
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
|
||||
import './controller.dart';
|
||||
import 'package:PiliPlus/common/widgets/spring_physics.dart';
|
||||
|
||||
class HomePage extends StatefulWidget {
|
||||
const HomePage({super.key});
|
||||
@@ -73,6 +74,7 @@ class _HomePageState extends State<HomePage>
|
||||
const SizedBox(height: 6),
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
physics: customTabBarViewScrollPhysics,
|
||||
controller: _homeController.tabController,
|
||||
children: _homeController.tabsPageList,
|
||||
),
|
||||
|
||||
@@ -16,6 +16,7 @@ import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:extended_nested_scroll_view/extended_nested_scroll_view.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:PiliPlus/common/widgets/spring_physics.dart';
|
||||
|
||||
class MemberPageNew extends StatefulWidget {
|
||||
const MemberPageNew({super.key});
|
||||
@@ -151,6 +152,7 @@ class _MemberPageNewState extends State<MemberPageNew>
|
||||
top: false,
|
||||
bottom: false,
|
||||
child: TabBarView(
|
||||
physics: customTabBarViewScrollPhysics,
|
||||
controller: _userController.tabController,
|
||||
children: _userController.tab2!.map((item) {
|
||||
return switch (item.param!) {
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:PiliPlus/pages/member_search/search_dynamic.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'controller.dart';
|
||||
import 'package:PiliPlus/common/widgets/spring_physics.dart';
|
||||
|
||||
class MemberSearchPage extends StatefulWidget {
|
||||
const MemberSearchPage({super.key});
|
||||
@@ -69,6 +70,7 @@ class _MemberSearchPageState extends State<MemberSearchPage> {
|
||||
),
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
physics: customTabBarViewScrollPhysics,
|
||||
controller: _memberSearchCtr.tabController,
|
||||
children: [
|
||||
SearchArchive(ctr: _memberSearchCtr),
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:get/get.dart';
|
||||
import 'package:PiliPlus/models/common/search_type.dart';
|
||||
import 'package:PiliPlus/pages/search_panel/index.dart';
|
||||
import 'controller.dart';
|
||||
import 'package:PiliPlus/common/widgets/spring_physics.dart';
|
||||
|
||||
class SearchResultPage extends StatefulWidget {
|
||||
const SearchResultPage({super.key});
|
||||
@@ -119,6 +120,7 @@ class _SearchResultPageState extends State<SearchResultPage>
|
||||
),
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
physics: customTabBarViewScrollPhysics,
|
||||
controller: _tabController,
|
||||
children: SearchType.values
|
||||
.map(
|
||||
|
||||
@@ -536,6 +536,75 @@ List<SettingsModel> get styleSettings => [
|
||||
getSubtitle: () =>
|
||||
'当前启动页:${defaultNavigationBars.firstWhere((e) => e['id'] == GStorage.defaultHomePage)['label']}',
|
||||
),
|
||||
SettingsModel(
|
||||
settingsType: SettingsType.normal,
|
||||
title: '滑动动画弹簧参数',
|
||||
leading: const Icon(Icons.chrome_reader_mode_outlined),
|
||||
onTap: (setState) {
|
||||
final numberRegExp = RegExp(r'[\d\.]+');
|
||||
List springDescription = GStorage.springDescription.map((i) => i.toString()).toList();
|
||||
showDialog(
|
||||
context: Get.context!,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: const Text('弹簧参数'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextFormField(
|
||||
autofocus: true,
|
||||
initialValue: springDescription[0],
|
||||
keyboardType: TextInputType.numberWithOptions(),
|
||||
onChanged: (value) { springDescription[0] = value; },
|
||||
inputFormatters: [FilteringTextInputFormatter.allow(numberRegExp)],
|
||||
decoration: InputDecoration(labelText: 'mass'),
|
||||
),
|
||||
TextFormField(
|
||||
autofocus: true,
|
||||
initialValue: springDescription[1],
|
||||
keyboardType: TextInputType.numberWithOptions(),
|
||||
onChanged: (value) { springDescription[1] = value; },
|
||||
inputFormatters: [FilteringTextInputFormatter.allow(numberRegExp)],
|
||||
decoration: InputDecoration(labelText: 'stiffness'),
|
||||
),
|
||||
TextFormField(
|
||||
autofocus: true,
|
||||
initialValue: springDescription[2],
|
||||
keyboardType: TextInputType.numberWithOptions(),
|
||||
onChanged: (value) { springDescription[2] = value; },
|
||||
inputFormatters: [FilteringTextInputFormatter.allow(numberRegExp)],
|
||||
decoration: InputDecoration(labelText: 'damping'),
|
||||
)
|
||||
]
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: Get.back,
|
||||
child: Text(
|
||||
'取消',
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.outline,
|
||||
),
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
Get.back();
|
||||
await GStorage.setting.put(
|
||||
SettingBoxKey.springDescription,
|
||||
List<double>.generate(3, (i) => double.tryParse(springDescription[i]) ?? GStorage.springDescription[i]),
|
||||
);
|
||||
SmartDialog.showToast('设置成功,重启生效');
|
||||
setState();
|
||||
},
|
||||
child: const Text('确定'),
|
||||
)
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
SettingsModel(
|
||||
settingsType: SettingsType.normal,
|
||||
onTap: (setState) async {
|
||||
|
||||
@@ -50,6 +50,7 @@ import 'package:screen_brightness/screen_brightness.dart';
|
||||
|
||||
import '../../../services/shutdown_timer_service.dart';
|
||||
import 'widgets/header_control.dart';
|
||||
import 'package:PiliPlus/common/widgets/spring_physics.dart';
|
||||
|
||||
class VideoDetailPage extends StatefulWidget {
|
||||
const VideoDetailPage({super.key});
|
||||
@@ -621,7 +622,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
),
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
physics: const ClampingScrollPhysics(),
|
||||
physics: customTabBarViewScrollPhysics,
|
||||
controller: videoDetailController.tabCtr,
|
||||
children: [
|
||||
videoIntro(),
|
||||
@@ -672,7 +673,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
buildTabbar(showReply: videoDetailController.showReply),
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
physics: const ClampingScrollPhysics(),
|
||||
physics: customTabBarViewScrollPhysics,
|
||||
controller: videoDetailController.tabCtr,
|
||||
children: [
|
||||
videoIntro(),
|
||||
@@ -772,6 +773,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
),
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
physics: customTabBarViewScrollPhysics,
|
||||
controller: videoDetailController.tabCtr,
|
||||
children: [
|
||||
if (videoDetailController.showReply)
|
||||
@@ -881,7 +883,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
),
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
physics: const ClampingScrollPhysics(),
|
||||
physics: customTabBarViewScrollPhysics,
|
||||
controller: videoDetailController.tabCtr,
|
||||
children: [
|
||||
if (videoDetailController.videoType ==
|
||||
|
||||
@@ -415,6 +415,12 @@ class GStorage {
|
||||
};
|
||||
}
|
||||
|
||||
static final _defaultSpring = const ClampingScrollPhysics().spring;
|
||||
|
||||
static final List springDescription = setting
|
||||
.get(SettingBoxKey.springDescription,
|
||||
defaultValue: [_defaultSpring.mass, _defaultSpring.stiffness, _defaultSpring.damping]);
|
||||
|
||||
// static Brightness get brightness {
|
||||
// return switch (_themeMode) {
|
||||
// 0 => Brightness.light,
|
||||
@@ -625,6 +631,7 @@ class SettingBoxKey {
|
||||
antiGoodsDyn = 'antiGoodsDyn',
|
||||
antiGoodsReply = 'antiGoodsReply',
|
||||
expandDynLivePanel = 'expandDynLivePanel',
|
||||
springDescription = 'springDescription',
|
||||
|
||||
// Sponsor Block
|
||||
enableSponsorBlock = 'enableSponsorBlock',
|
||||
|
||||
Reference in New Issue
Block a user