Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Call back for stop floating added #12

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions lib/src/constants.dart
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
const defaultAnimationDuration = Duration(milliseconds: 200);
const double defaultFloatingBorderRadius = 10;
6 changes: 6 additions & 0 deletions lib/src/pip_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ class PIPView extends StatefulWidget {
final PIPViewCorner initialCorner;
final double? floatingWidth;
final double? floatingHeight;
final double? floatingBorderRadius;
final bool avoidKeyboard;
final VoidCallback? onStopFloating;

final Widget Function(
BuildContext context,
Expand All @@ -20,7 +22,9 @@ class PIPView extends StatefulWidget {
this.initialCorner = PIPViewCorner.topRight,
this.floatingWidth,
this.floatingHeight,
this.floatingBorderRadius,
this.avoidKeyboard = true,
this.onStopFloating,
}) : super(key: key);

@override
Expand All @@ -42,6 +46,7 @@ class PIPViewState extends State<PIPView> with TickerProviderStateMixin {
void stopFloating() {
dismissKeyboard(context);
setState(() => _bottomWidget = null);
widget.onStopFloating?.call();
}

@override
Expand All @@ -65,6 +70,7 @@ class PIPViewState extends State<PIPView> with TickerProviderStateMixin {
),
floatingHeight: widget.floatingHeight,
floatingWidth: widget.floatingWidth,
floatingBorderRadius: widget.floatingBorderRadius,
initialCorner: widget.initialCorner,
);
}
Expand Down
24 changes: 14 additions & 10 deletions lib/src/raw_pip_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class RawPIPView extends StatefulWidget {
final PIPViewCorner initialCorner;
final double? floatingWidth;
final double? floatingHeight;
final double? floatingBorderRadius;
final bool avoidKeyboard;
final Widget? topWidget;
final Widget? bottomWidget;
Expand All @@ -20,11 +21,13 @@ class RawPIPView extends StatefulWidget {
this.initialCorner = PIPViewCorner.topRight,
this.floatingWidth,
this.floatingHeight,
this.floatingBorderRadius,
this.avoidKeyboard = true,
this.topWidget,
this.bottomWidget,
this.onTapTopWidget,
}) : super(key: key);
}) :
super(key: key);

@override
RawPIPViewState createState() => RawPIPViewState();
Expand Down Expand Up @@ -200,14 +203,15 @@ class RawPIPViewState extends State<RawPIPView> with TickerProviderStateMixin {
final floatingOffset = _isDragging
? _dragOffset
: Tween<Offset>(
begin: _dragOffset,
end: calculatedOffset,
).transform(_dragAnimationController.isAnimating
? dragAnimationValue
: toggleFloatingAnimationValue);
begin: _dragOffset,
end: calculatedOffset,
).transform(_dragAnimationController.isAnimating
? dragAnimationValue
: toggleFloatingAnimationValue);
final borderRadius = Tween<double>(
begin: 0,
end: 10,
end: widget.floatingBorderRadius ??
defaultFloatingBorderRadius,
).transform(toggleFloatingAnimationValue);
final width = Tween<double>(
begin: fullWidgetSize.width,
Expand Down Expand Up @@ -287,9 +291,9 @@ PIPViewCorner _calculateNearestCorner({
_CornerDistance calculateDistance(PIPViewCorner corner) {
final distance = offsets[corner]!
.translate(
-offset.dx,
-offset.dy,
)
-offset.dx,
-offset.dy,
)
.distanceSquared;
return _CornerDistance(
corner: corner,
Expand Down