Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor #95

Merged
merged 9 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Rename SheetExtentFactory to SheetExtentConfig
  • Loading branch information
fujidaiti committed Apr 18, 2024
commit bc8e0bd0d006c611148c93e237561f5dcb94b500
8 changes: 4 additions & 4 deletions package/lib/src/draggable/draggable_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class DraggableSheet extends StatelessWidget {

Widget result = SheetContainer(
controller: controller,
factory: DraggableSheetExtentFactory(
config: DraggableSheetExtentConfig(
initialExtent: initialExtent,
minExtent: minExtent,
maxExtent: maxExtent,
Expand All @@ -89,9 +89,9 @@ class DraggableSheet extends StatelessWidget {
}
}

/// Factory of [DraggableSheetExtent].
class DraggableSheetExtentFactory extends SheetExtentFactory {
const DraggableSheetExtentFactory({
/// A configuration of a [DraggableSheetExtent].
class DraggableSheetExtentConfig extends SheetExtentConfig {
const DraggableSheetExtentConfig({
required this.initialExtent,
required this.minExtent,
required this.maxExtent,
Expand Down
6 changes: 3 additions & 3 deletions package/lib/src/foundation/framework.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ class SheetContainer extends StatelessWidget {
super.key,
this.controller,
this.onExtentChanged,
required this.factory,
required this.config,
required this.child,
});

final SheetController? controller;
final ValueChanged<SheetExtent?>? onExtentChanged;
final SheetExtentFactory factory;
final SheetExtentConfig config;
final Widget child;

@override
Widget build(BuildContext context) {
return SheetExtentScope(
factory: factory,
config: config,
controller: controller ?? SheetControllerScope.maybeOf(context),
onExtentChanged: onExtentChanged,
child: Builder(
Expand Down
26 changes: 13 additions & 13 deletions package/lib/src/foundation/sheet_extent.dart
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,9 @@ abstract class SheetContext {
BuildContext? get notificationContext;
}

/// A factory that creates a [SheetExtent].
abstract class SheetExtentFactory {
const SheetExtentFactory();
/// Configuration of a [SheetExtent].
abstract class SheetExtentConfig {
const SheetExtentConfig();
SheetExtent build(BuildContext context, SheetContext sheetContext);
bool shouldRebuild(BuildContext context, SheetExtent oldExtent);
}
Expand All @@ -643,7 +643,7 @@ class SheetExtentScope extends StatefulWidget {
/// Creates a widget that hosts a [SheetExtent].
const SheetExtentScope({
super.key,
required this.factory,
required this.config,
this.controller,
this.onExtentChanged,
required this.child,
Expand All @@ -652,11 +652,11 @@ class SheetExtentScope extends StatefulWidget {
/// The [SheetController] that will be attached to the created [SheetExtent].
final SheetController? controller;

/// The factory that creates the [SheetExtent].
/// The configuration of the [SheetExtent] manged by this widget.
///
/// The [SheetExtentScope] will recreate the [SheetExtent] whenever
/// it is rebuilt with a [factory] that is not identical to the previous one.
final SheetExtentFactory factory;
/// it is rebuilt with a [config] that is not identical to the previous one.
final SheetExtentConfig config;

/// Called whenever the [SheetExtent] changes.
///
Expand All @@ -676,7 +676,7 @@ class SheetExtentScope extends StatefulWidget {
/// that encloses the given context, if any.
///
/// Use of this method will cause the given context to rebuild any time
/// that the [factory] property of the ancestor [SheetExtentScope] changes.
/// that the [config] property of the ancestor [SheetExtentScope] changes.
// TODO: Add 'useRoot' option
static SheetExtent? maybeOf(BuildContext context) {
return context
Expand All @@ -688,7 +688,7 @@ class SheetExtentScope extends StatefulWidget {
/// that encloses the given context.
///
/// Use of this method will cause the given context to rebuild any time
/// that the [factory] property of the ancestor [SheetExtentScope] changes.
/// that the [config] property of the ancestor [SheetExtentScope] changes.
static SheetExtent of(BuildContext context) {
return maybeOf(context)!;
}
Expand Down Expand Up @@ -718,8 +718,8 @@ class _SheetExtentScopeState extends State<SheetExtentScope>
void didChangeDependencies() {
super.didChangeDependencies();
final oldExtent = _extent;
if (oldExtent == null || widget.factory.shouldRebuild(context, oldExtent)) {
final newExtent = widget.factory.build(context, this);
if (oldExtent == null || widget.config.shouldRebuild(context, oldExtent)) {
final newExtent = widget.config.build(context, this);
widget.controller?.attach(newExtent);
widget.onExtentChanged?.call(newExtent);
_extent = newExtent;
Expand All @@ -732,8 +732,8 @@ class _SheetExtentScopeState extends State<SheetExtentScope>
assert(_extent != null);
final oldExtent = _extent!;

if (widget.factory.shouldRebuild(context, oldExtent)) {
_extent = widget.factory.build(context, this)..takeOver(oldExtent);
if (widget.config.shouldRebuild(context, oldExtent)) {
_extent = widget.config.build(context, this)..takeOver(oldExtent);
widget.onExtentChanged?.call(_extent);
}

Expand Down
4 changes: 2 additions & 2 deletions package/lib/src/navigation/navigation_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:smooth_sheets/src/foundation/sheet_status.dart';
import 'package:smooth_sheets/src/navigation/navigation_sheet.dart';

mixin NavigationSheetRouteMixin<T> on NavigationSheetRoute<T> {
SheetExtentFactory get pageExtentFactory;
SheetExtentConfig get pageExtentConfig;

@override
NavigationSheetExtentDelegate get pageExtent => _pageExtent;
Expand Down Expand Up @@ -39,7 +39,7 @@ mixin NavigationSheetRouteMixin<T> on NavigationSheetRoute<T> {
Animation<double> secondaryAnimation,
) {
return SheetExtentScope(
factory: pageExtentFactory,
config: pageExtentConfig,
onExtentChanged: (extent) => _pageExtent.source = extent,
child: SheetContentViewport(
child: buildContent(context),
Expand Down
36 changes: 18 additions & 18 deletions package/lib/src/navigation/navigation_routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ class ScrollableNavigationSheetRoute<T> extends NavigationSheetRoute<T>
this.physics = const StretchingSheetPhysics(parent: SnappingSheetPhysics()),
this.transitionsBuilder,
required this.builder,
}) : pageExtentFactory = ScrollableSheetExtentFactory(
}) : pageExtentConfig = ScrollableSheetExtentConfig(
initialExtent: initialExtent,
minExtent: minExtent,
maxExtent: maxExtent,
physics: physics,
);

@override
final ScrollableSheetExtentFactory pageExtentFactory;
final ScrollableSheetExtentConfig pageExtentConfig;

final Extent initialExtent;
final Extent minExtent;
Expand Down Expand Up @@ -70,7 +70,7 @@ class DraggableNavigationSheetRoute<T> extends NavigationSheetRoute<T>
this.physics = const StretchingSheetPhysics(parent: SnappingSheetPhysics()),
this.transitionsBuilder,
required this.builder,
}) : pageExtentFactory = DraggableSheetExtentFactory(
}) : pageExtentConfig = DraggableSheetExtentConfig(
initialExtent: initialExtent,
minExtent: minExtent,
maxExtent: maxExtent,
Expand All @@ -93,7 +93,7 @@ class DraggableNavigationSheetRoute<T> extends NavigationSheetRoute<T>
final WidgetBuilder builder;

@override
final DraggableSheetExtentFactory pageExtentFactory;
final DraggableSheetExtentConfig pageExtentConfig;

@override
Widget buildContent(BuildContext context) {
Expand Down Expand Up @@ -168,17 +168,17 @@ class _PageBasedScrollableNavigationSheetRoute<T>
Duration get transitionDuration => page.transitionDuration;

@override
ScrollableSheetExtentFactory get pageExtentFactory => _pageExtentFactory!;
ScrollableSheetExtentFactory? _pageExtentFactory;
ScrollableSheetExtentConfig get pageExtentConfig => _pageExtentConfig!;
ScrollableSheetExtentConfig? _pageExtentConfig;

@override
void changedInternalState() {
super.changedInternalState();
if (page.initialExtent != _pageExtentFactory?.initialExtent ||
page.minExtent != _pageExtentFactory?.minExtent ||
page.maxExtent != _pageExtentFactory?.maxExtent ||
page.physics != _pageExtentFactory?.physics) {
_pageExtentFactory = ScrollableSheetExtentFactory(
if (page.initialExtent != _pageExtentConfig?.initialExtent ||
page.minExtent != _pageExtentConfig?.minExtent ||
page.maxExtent != _pageExtentConfig?.maxExtent ||
page.physics != _pageExtentConfig?.physics) {
_pageExtentConfig = ScrollableSheetExtentConfig(
initialExtent: page.initialExtent,
minExtent: page.minExtent,
maxExtent: page.maxExtent,
Expand Down Expand Up @@ -260,17 +260,17 @@ class _PageBasedDraggableNavigationSheetRoute<T> extends NavigationSheetRoute<T>
Duration get transitionDuration => page.transitionDuration;

@override
DraggableSheetExtentFactory get pageExtentFactory => _pageExtentFactory!;
DraggableSheetExtentFactory? _pageExtentFactory;
DraggableSheetExtentConfig get pageExtentConfig => _pageExtentConfig!;
DraggableSheetExtentConfig? _pageExtentConfig;

@override
void changedInternalState() {
super.changedInternalState();
if (page.initialExtent != _pageExtentFactory?.initialExtent ||
page.minExtent != _pageExtentFactory?.minExtent ||
page.maxExtent != _pageExtentFactory?.maxExtent ||
page.physics != _pageExtentFactory?.physics) {
_pageExtentFactory = DraggableSheetExtentFactory(
if (page.initialExtent != _pageExtentConfig?.initialExtent ||
page.minExtent != _pageExtentConfig?.minExtent ||
page.maxExtent != _pageExtentConfig?.maxExtent ||
page.physics != _pageExtentConfig?.physics) {
_pageExtentConfig = DraggableSheetExtentConfig(
initialExtent: page.initialExtent,
minExtent: page.minExtent,
maxExtent: page.maxExtent,
Expand Down
6 changes: 3 additions & 3 deletions package/lib/src/navigation/navigation_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class NavigationSheetState extends State<NavigationSheet>
widget.keyboardDismissBehavior ?? theme?.keyboardDismissBehavior;

Widget result = SheetContainer(
factory: const _NavigationSheetExtentFactory(),
config: const _NavigationSheetExtentConfig(),
controller: widget.controller,
onExtentChanged: (extent) {
_extent = extent as _NavigationSheetExtent?;
Expand Down Expand Up @@ -139,8 +139,8 @@ abstract class NavigationSheetExtentDelegate implements Listenable {
void beginActivity(SheetActivity activity);
}

class _NavigationSheetExtentFactory extends SheetExtentFactory {
const _NavigationSheetExtentFactory();
class _NavigationSheetExtentConfig extends SheetExtentConfig {
const _NavigationSheetExtentConfig();

@override
bool shouldRebuild(BuildContext context, SheetExtent oldExtent) {
Expand Down
2 changes: 1 addition & 1 deletion package/lib/src/scrollable/scrollable_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ScrollableSheet extends StatelessWidget {

Widget result = SheetContainer(
controller: controller,
factory: ScrollableSheetExtentFactory(
config: ScrollableSheetExtentConfig(
initialExtent: initialExtent,
minExtent: minExtent,
maxExtent: maxExtent,
Expand Down
4 changes: 2 additions & 2 deletions package/lib/src/scrollable/scrollable_sheet_extent.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import 'package:smooth_sheets/src/internal/double_utils.dart';
import 'package:smooth_sheets/src/scrollable/delegatable_scroll_position.dart';
import 'package:smooth_sheets/src/scrollable/scrollable_sheet_physics.dart';

class ScrollableSheetExtentFactory extends SheetExtentFactory {
const ScrollableSheetExtentFactory({
class ScrollableSheetExtentConfig extends SheetExtentConfig {
const ScrollableSheetExtentConfig({
required this.initialExtent,
required this.minExtent,
required this.maxExtent,
Expand Down