Unverified Commit 3dbec840 authored by xster's avatar xster Committed by GitHub

Small cleanup in CupertinoSliverRefreshControl (#27570)

parent b06a7093
...@@ -27,6 +27,7 @@ class _CupertinoSliverRefresh extends SingleChildRenderObjectWidget { ...@@ -27,6 +27,7 @@ class _CupertinoSliverRefresh extends SingleChildRenderObjectWidget {
// The amount of space the indicator should occupy in the sliver in a // The amount of space the indicator should occupy in the sliver in a
// resting state when in the refreshing mode. // resting state when in the refreshing mode.
final double refreshIndicatorLayoutExtent; final double refreshIndicatorLayoutExtent;
// _RenderCupertinoSliverRefresh will paint the child in the available // _RenderCupertinoSliverRefresh will paint the child in the available
// space either way but this instructs the _RenderCupertinoSliverRefresh // space either way but this instructs the _RenderCupertinoSliverRefresh
// on whether to also occupy any layoutExtent space or not. // on whether to also occupy any layoutExtent space or not.
...@@ -82,8 +83,8 @@ class _RenderCupertinoSliverRefresh extends RenderSliver ...@@ -82,8 +83,8 @@ class _RenderCupertinoSliverRefresh extends RenderSliver
} }
// The child box will be laid out and painted in the available space either // The child box will be laid out and painted in the available space either
// way but this determines whether to also occupy any layoutExtent space or // way but this determines whether to also occupy any
// not. // [SliverGeometry.layoutExtent] space or not.
bool get hasLayoutExtent => _hasLayoutExtent; bool get hasLayoutExtent => _hasLayoutExtent;
bool _hasLayoutExtent; bool _hasLayoutExtent;
set hasLayoutExtent(bool value) { set hasLayoutExtent(bool value) {
...@@ -268,7 +269,7 @@ class CupertinoSliverRefreshControl extends StatefulWidget { ...@@ -268,7 +269,7 @@ class CupertinoSliverRefreshControl extends StatefulWidget {
/// Create a new refresh control for inserting into a list of slivers. /// Create a new refresh control for inserting into a list of slivers.
/// ///
/// The [refreshTriggerPullDistance] and [refreshIndicatorExtent] arguments /// The [refreshTriggerPullDistance] and [refreshIndicatorExtent] arguments
/// must not be null. /// must not be null and must be >= 0.
/// ///
/// The [builder] argument may be null, in which case no indicator UI will be /// The [builder] argument may be null, in which case no indicator UI will be
/// shown but the [onRefresh] will still be invoked. By default, [builder] /// shown but the [onRefresh] will still be invoked. By default, [builder]
...@@ -389,8 +390,8 @@ class CupertinoSliverRefreshControl extends StatefulWidget { ...@@ -389,8 +390,8 @@ class CupertinoSliverRefreshControl extends StatefulWidget {
} }
class _CupertinoSliverRefreshControlState extends State<CupertinoSliverRefreshControl> { class _CupertinoSliverRefreshControlState extends State<CupertinoSliverRefreshControl> {
/// Reset the state from done to inactive when only this fraction of the // Reset the state from done to inactive when only this fraction of the
/// original `refreshTriggerPullDistance` is left. // original `refreshTriggerPullDistance` is left.
static const double _inactiveResetOverscrollFraction = 0.1; static const double _inactiveResetOverscrollFraction = 0.1;
RefreshIndicatorMode refreshState; RefreshIndicatorMode refreshState;
...@@ -399,12 +400,12 @@ class _CupertinoSliverRefreshControlState extends State<CupertinoSliverRefreshCo ...@@ -399,12 +400,12 @@ class _CupertinoSliverRefreshControlState extends State<CupertinoSliverRefreshCo
// The amount of space available from the inner indicator box's perspective. // The amount of space available from the inner indicator box's perspective.
// //
// The value is the sum of the sliver's layout extent and the overscroll // The value is the sum of the sliver's layout extent and the overscroll
// (which partially gets transfered into the layout extent when the refresh // (which partially gets transferred into the layout extent when the refresh
// triggers). // triggers).
// //
// The value of lastIndicatorExtent doesn't change when the sliver scrolls // The value of latestIndicatorBoxExtent doesn't change when the sliver scrolls
// away without retracting; it is independent from the sliver's scrollOffset. // away without retracting; it is independent from the sliver's scrollOffset.
double lastIndicatorExtent = 0.0; double latestIndicatorBoxExtent = 0.0;
bool hasSliverLayoutExtent = false; bool hasSliverLayoutExtent = false;
@override @override
...@@ -433,7 +434,7 @@ class _CupertinoSliverRefreshControlState extends State<CupertinoSliverRefreshCo ...@@ -433,7 +434,7 @@ class _CupertinoSliverRefreshControlState extends State<CupertinoSliverRefreshCo
switch (refreshState) { switch (refreshState) {
case RefreshIndicatorMode.inactive: case RefreshIndicatorMode.inactive:
if (lastIndicatorExtent <= 0) { if (latestIndicatorBoxExtent <= 0) {
return RefreshIndicatorMode.inactive; return RefreshIndicatorMode.inactive;
} else { } else {
nextState = RefreshIndicatorMode.drag; nextState = RefreshIndicatorMode.drag;
...@@ -441,9 +442,9 @@ class _CupertinoSliverRefreshControlState extends State<CupertinoSliverRefreshCo ...@@ -441,9 +442,9 @@ class _CupertinoSliverRefreshControlState extends State<CupertinoSliverRefreshCo
continue drag; continue drag;
drag: drag:
case RefreshIndicatorMode.drag: case RefreshIndicatorMode.drag:
if (lastIndicatorExtent == 0) { if (latestIndicatorBoxExtent == 0) {
return RefreshIndicatorMode.inactive; return RefreshIndicatorMode.inactive;
} else if (lastIndicatorExtent < widget.refreshTriggerPullDistance) { } else if (latestIndicatorBoxExtent < widget.refreshTriggerPullDistance) {
return RefreshIndicatorMode.drag; return RefreshIndicatorMode.drag;
} else { } else {
if (widget.onRefresh != null) { if (widget.onRefresh != null) {
...@@ -476,7 +477,7 @@ class _CupertinoSliverRefreshControlState extends State<CupertinoSliverRefreshCo ...@@ -476,7 +477,7 @@ class _CupertinoSliverRefreshControlState extends State<CupertinoSliverRefreshCo
continue done; continue done;
} }
if (lastIndicatorExtent > widget.refreshIndicatorExtent) { if (latestIndicatorBoxExtent > widget.refreshIndicatorExtent) {
return RefreshIndicatorMode.armed; return RefreshIndicatorMode.armed;
} else { } else {
nextState = RefreshIndicatorMode.refresh; nextState = RefreshIndicatorMode.refresh;
...@@ -496,7 +497,7 @@ class _CupertinoSliverRefreshControlState extends State<CupertinoSliverRefreshCo ...@@ -496,7 +497,7 @@ class _CupertinoSliverRefreshControlState extends State<CupertinoSliverRefreshCo
// to 0.0 since the last bit of the animation can take some time and // to 0.0 since the last bit of the animation can take some time and
// can feel sluggish if not going all the way back to 0.0 prevented // can feel sluggish if not going all the way back to 0.0 prevented
// a subsequent pull-to-refresh from starting. // a subsequent pull-to-refresh from starting.
if (lastIndicatorExtent > if (latestIndicatorBoxExtent >
widget.refreshTriggerPullDistance * _inactiveResetOverscrollFraction) { widget.refreshTriggerPullDistance * _inactiveResetOverscrollFraction) {
return RefreshIndicatorMode.done; return RefreshIndicatorMode.done;
} else { } else {
...@@ -517,13 +518,13 @@ class _CupertinoSliverRefreshControlState extends State<CupertinoSliverRefreshCo ...@@ -517,13 +518,13 @@ class _CupertinoSliverRefreshControlState extends State<CupertinoSliverRefreshCo
// its owner to trigger state changes. // its owner to trigger state changes.
child: LayoutBuilder( child: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) { builder: (BuildContext context, BoxConstraints constraints) {
lastIndicatorExtent = constraints.maxHeight; latestIndicatorBoxExtent = constraints.maxHeight;
refreshState = transitionNextState(); refreshState = transitionNextState();
if (widget.builder != null && refreshState != RefreshIndicatorMode.inactive) { if (widget.builder != null && refreshState != RefreshIndicatorMode.inactive) {
return widget.builder( return widget.builder(
context, context,
refreshState, refreshState,
lastIndicatorExtent, latestIndicatorBoxExtent,
widget.refreshTriggerPullDistance, widget.refreshTriggerPullDistance,
widget.refreshIndicatorExtent, widget.refreshIndicatorExtent,
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment