Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 24 additions & 25 deletions lib/navigation/view/main_window_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4003,32 +4003,31 @@ class MainWindowScreenState extends State<MainWindowScreen>
width: 1,
),
),
// ילד קבוע ב-Row: הסתרה היא רוחב 0 ולא
// הוצאה מהעץ, אחרת ה-PageView נבנה
// מחדש והמסכים מאבדים State.
ReadingTabsSidePanel(
show:
isLandscape &&
!isImmersive &&
hasOpenTabs &&
(state.currentScreen ==
Screen.reading ||
state.currentScreen ==
Screen.search) &&
context.select<
SettingsBloc,
bool
>(
(b) => b
.state
.readingTabsOnSide,
),
),
Expanded(
child: RepaintBoundary(
key: _windowKeys
.windowContentBoundary,
child: pageView,
child: ReadingTabsSidePanel(
show:
isLandscape &&
!isImmersive &&
hasOpenTabs &&
(state.currentScreen ==
Screen
.reading ||
state.currentScreen ==
Screen
.search) &&
context.select<
SettingsBloc,
bool
>(
(b) => b
.state
.readingTabsOnSide,
),
child: RepaintBoundary(
key: _windowKeys
.windowContentBoundary,
child: pageView,
),
),
),
],
Expand Down
209 changes: 164 additions & 45 deletions lib/navigation/view/reading_tabs_side_panel.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import 'dart:async';

import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:otzaria/core/windowing/app_window_keys.dart';
Expand All @@ -15,28 +18,28 @@ import 'package:otzaria/theme/app_tokens.dart';
import 'package:otzaria/widgets/layout/resizable_drag_handle.dart';
import 'package:otzaria/widgets/misc/rtl_icon.dart';

/// עמודת כרטיסיות העיון שבין סרגל הניווט לתוכן המסך.
///
/// חייבת להישאר ילד קבוע ב-Row של המסך הראשי: היעלמות מהעץ בונה מחדש את
/// ה-PageView ומאבדת את ה-State של הכרטיסיות. לכן ההסתרה היא רוחב מונפש ל-0.
/// עמודת כרטיסיות קבועה מעל התוכן; ריחוף אינו משנה את המקום השמור לצדה.
class ReadingTabsSidePanel extends StatefulWidget {
final bool show;
final Widget child;

const ReadingTabsSidePanel({super.key, required this.show});
const ReadingTabsSidePanel({
super.key,
required this.show,
required this.child,
});

@override
State<ReadingTabsSidePanel> createState() => _ReadingTabsSidePanelState();
}

class _ReadingTabsSidePanelState extends State<ReadingTabsSidePanel> {
/// הרוחב בזמן גרירה בלבד — האירוע ל-Bloc נשלח רק בסופה, כדי לא לשמור
/// בהגדרות בכל תזוזת מצביע.
///
/// [ValueNotifier] ולא שדה שנקרא ב-build: שני אירועי תזוזה באותו פריים קוראים
/// את הערך המעודכן, אחרת הדלתא הראשונה נמחקת והעמודה מפגרת אחרי הסמן.
/// ערך חי מונע אובדן דלתאות באותו פריים; ההגדרה נשמרת רק בסיום גרירה.
final ValueNotifier<double?> _draggingWidth = ValueNotifier(null);

/// לא בונים את תוכן העמודה לפני שהוצגה לראשונה.
final Set<int> _pressedPointers = {};
Timer? _hoverTimer;
bool _hovered = false;
bool _hoverExpanded = false;
bool _everShown = false;

@override
Expand All @@ -49,14 +52,38 @@ class _ReadingTabsSidePanelState extends State<ReadingTabsSidePanel> {
void didUpdateWidget(ReadingTabsSidePanel oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.show && !_everShown) _everShown = true;
if (!widget.show) {
_hoverTimer?.cancel();
_hovered = false;
_hoverExpanded = false;
_pressedPointers.clear();
}
}

@override
void dispose() {
_hoverTimer?.cancel();
_draggingWidth.dispose();
super.dispose();
}

void _updateHover() {
_hoverTimer?.cancel();
if (!mounted || !widget.show || _pressedPointers.isNotEmpty) return;
final expand =
_hovered &&
context.read<SettingsBloc>().state.readingTabsColumnCollapsed;
if (_hoverExpanded == expand) return;
_hoverTimer = Timer(AppTokens.animNormal, () {
if (mounted) setState(() => _hoverExpanded = expand);
});
}

void _onPointerReleased(PointerEvent event) {
_pressedPointers.remove(event.pointer);
_updateHover();
}

void _onDragStart(double current) => _draggingWidth.value = current;

void _onDragDelta(double delta) {
Expand Down Expand Up @@ -89,27 +116,101 @@ class _ReadingTabsSidePanelState extends State<ReadingTabsSidePanel> {

return ValueListenableBuilder<double?>(
valueListenable: _draggingWidth,
builder: (context, dragging, _) {
final width = collapsed
? kCollapsedTabsColumnWidth
: (dragging ?? savedWidth);

return AnimatedContainer(
// בזמן גרירת הידית הרוחב עוקב אחרי הסמן מיידית; ההנפשה שמורה
// להצגה/הסתרה ולכיווץ.
duration: dragging == null ? AppTokens.animPanelSlide : Duration.zero,
curve: Curves.easeInOut,
width: widget.show ? width : 0,
child: ClipRect(
child: OverflowBox(
minWidth: 0,
maxWidth: width,
alignment: AlignmentDirectional.centerStart,
child: _everShown
? _buildContent(context, width: width, collapsed: collapsed)
: const SizedBox.shrink(),
),
),
child: widget.child,
builder: (context, dragging, child) {
return LayoutBuilder(
builder: (context, constraints) {
final expandedWidth = (dragging ?? savedWidth).clamp(
0.0,
constraints.maxWidth,
);
final floating = collapsed && _hoverExpanded;
final visuallyCollapsed = collapsed && !floating;
final width = visuallyCollapsed
? kCollapsedTabsColumnWidth
: expandedWidth;
final reservedWidth = collapsed
? kCollapsedTabsColumnWidth
: expandedWidth;
final duration = dragging == null
? AppTokens.animPanelSlide
: Duration.zero;

return Stack(
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
AnimatedContainer(
duration: duration,
curve: Curves.easeInOut,
width: widget.show ? reservedWidth : 0,
),
Expanded(child: child!),
],
),
// העמודה והתוכן נשארים באותם סלוטים גם בהסתרה ובנעיצה.
PositionedDirectional(
start: 0,
top: 0,
bottom: 0,
child: IgnorePointer(
ignoring: !widget.show,
child: ExcludeFocus(
excluding: !widget.show,
child: ExcludeSemantics(
excluding: !widget.show,
child: MouseRegion(
onEnter: (event) {
if (event.kind != PointerDeviceKind.mouse) return;
_hovered = true;
_updateHover();
},
onExit: (event) {
if (event.kind != PointerDeviceKind.mouse) return;
_hovered = false;
_updateHover();
},
child: Listener(
onPointerDown: (event) {
_pressedPointers.add(event.pointer);
_hoverTimer?.cancel();
},
onPointerUp: _onPointerReleased,
onPointerCancel: _onPointerReleased,
child: AnimatedContainer(
duration: duration,
curve: Curves.easeInOut,
width: widget.show ? width : 0,
child: Material(
color: AppSurfaces.panelBackground(context),
elevation: floating ? AppTokens.elevation2 : 0,
child: ClipRect(
child: OverflowBox(
minWidth: width,
maxWidth: width,
alignment: AlignmentDirectional.centerStart,
child: _everShown
? _buildContent(
context,
width: width,
collapsed: visuallyCollapsed,
savedCollapsed: collapsed,
)
: const SizedBox.shrink(),
),
),
),
),
),
),
),
),
),
),
],
);
},
);
},
);
Expand All @@ -119,6 +220,7 @@ class _ReadingTabsSidePanelState extends State<ReadingTabsSidePanel> {
BuildContext context, {
required double width,
required bool collapsed,
required bool savedCollapsed,
}) {
return SizedBox(
width: width,
Expand All @@ -129,8 +231,12 @@ class _ReadingTabsSidePanelState extends State<ReadingTabsSidePanel> {
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_buildHeader(context, collapsed: collapsed),
_buildHeader(
context,
collapsed: savedCollapsed,
),
const Divider(height: 1),
Expanded(
child: KeyedSubtree(
Expand All @@ -144,10 +250,7 @@ class _ReadingTabsSidePanelState extends State<ReadingTabsSidePanel> {
],
),
),
// ידית שינוי הרוחב יושבת בקצה הפנימי (שמאל ב-RTL). במצב מכווץ
// הרוחב קבוע, ולכן הידית אינה נבנית כלל — אחרת היא גוזלת מרוחב
// העמודה הצרה ומזיזה את האייקונים מהמרכז.
if (!collapsed)
if (!savedCollapsed)
ResizableDragHandle(
isVertical: true,
showDivider: true,
Expand All @@ -161,9 +264,10 @@ class _ReadingTabsSidePanelState extends State<ReadingTabsSidePanel> {
);
}

/// שורת הכפתורים שבראש העמודה. במצב מכווץ אין מקום לשני כפתורים זה לצד זה,
/// ולכן הם נערמים זה מעל זה — וחיפוש הכרטיסיות נשאר נגיש.
Widget _buildHeader(BuildContext context, {required bool collapsed}) {
Widget _buildHeader(
BuildContext context, {
required bool collapsed,
}) {
return ListenableBuilder(
listenable: PluginNewTabPageRegistry.instance,
builder: (context, _) {
Expand All @@ -185,7 +289,15 @@ class _ReadingTabsSidePanelState extends State<ReadingTabsSidePanel> {
if (collapsed) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [for (final button in buttons) Center(child: button)],
crossAxisAlignment: CrossAxisAlignment.start,
// הכפתורים נשארים במקומם בריחוף, וכך גם הכרטיסיה שמתחת לסמן.
children: [
for (final button in buttons)
SizedBox(
width: kCollapsedTabsColumnWidth,
child: Center(child: button),
),
],
);
}
return SizedBox(
Expand All @@ -211,9 +323,16 @@ class _ReadingTabsSidePanelState extends State<ReadingTabsSidePanel> {
? FluentIcons.panel_left_24_regular
: FluentIcons.panel_right_24_regular,
),
onPressed: () => context.read<SettingsBloc>().add(
UpdateReadingTabsColumnCollapsed(!collapsed),
),
onPressed: () {
if (!collapsed) {
_hoverTimer?.cancel();
_hovered = false;
setState(() => _hoverExpanded = false);
}
context.read<SettingsBloc>().add(
UpdateReadingTabsColumnCollapsed(!collapsed),
);
},
);
}
}
8 changes: 3 additions & 5 deletions test/navigation/move_selected_tabs_to_workspace_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,9 @@ Future<_Env> _pumpStrip(
textDirection: TextDirection.rtl,
child: Scaffold(
body: onSide
? const Row(
children: [
ReadingTabsSidePanel(show: true),
Expanded(child: SizedBox.expand()),
],
? const ReadingTabsSidePanel(
show: true,
child: SizedBox.expand(),
)
: SizedBox(
width: 900,
Expand Down
Loading
Loading