Skip to content

Commit

Permalink
feat: Add video zoom functionality in lightbox
Browse files Browse the repository at this point in the history
Implements pinch-to-zoom and pan gestures for videos in the lightbox view.
This allows users to zoom in/out (up to 5x) and pan around while
maintaining proper aspect ratio.

Fixes zulip#1287
  • Loading branch information
XxAlonexX committed Jan 24, 2025
1 parent ae7939a commit 1688e61
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions lib/widgets/lightbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ class VideoLightboxPage extends StatefulWidget {

class _VideoLightboxPageState extends State<VideoLightboxPage> with PerAccountStoreAwareStateMixin<VideoLightboxPage> {
VideoPlayerController? _controller;
final TransformationController _transformationController = TransformationController();

@override
void onNewStore() {
Expand Down Expand Up @@ -494,6 +495,7 @@ class _VideoLightboxPageState extends State<VideoLightboxPage> with PerAccountSt
_controller?.removeListener(_handleVideoControllerUpdate);
_controller?.dispose();
_controller = null;
_transformationController.dispose();
// The VideoController doesn't emit a pause event
// while disposing, so disable the wakelock here
// explicitly.
Expand Down Expand Up @@ -546,21 +548,22 @@ class _VideoLightboxPageState extends State<VideoLightboxPage> with PerAccountSt
return _LightboxPageLayout(
routeEntranceAnimation: widget.routeEntranceAnimation,
message: widget.message,
buildAppBarBottom: (context) => null,
buildAppBarBottom: null,
buildBottomAppBar: _buildBottomAppBar,
child: SafeArea(
child: Center(
child: Stack(alignment: Alignment.center, children: [
if (_controller != null && _controller!.value.isInitialized)
AspectRatio(
child: _controller == null
? const Center(child: CircularProgressIndicator())
: Center(
child: InteractiveViewer(
transformationController: _transformationController,
minScale: 1.0,
maxScale: 5.0,
child: AspectRatio(
aspectRatio: _controller!.value.aspectRatio,
child: VideoPlayer(_controller!)),
if (_controller == null || !_controller!.value.isInitialized || _controller!.value.isBuffering)
const SizedBox(
width: 32,
height: 32,
child: CircularProgressIndicator(color: Colors.white)),
]))));
child: VideoPlayer(_controller!),
),
),
),
);
}
}

Expand Down

0 comments on commit 1688e61

Please sign in to comment.