Small cleanup in CupertinoSliverRefreshControl (#27570)

This commit is contained in:
xster 2019-02-05 19:12:37 -08:00 committed by GitHub
parent b06a709305
commit 3dbec84052
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -27,6 +27,7 @@ class _CupertinoSliverRefresh extends SingleChildRenderObjectWidget {
// The amount of space the indicator should occupy in the sliver in a
// resting state when in the refreshing mode.
final double refreshIndicatorLayoutExtent;
// _RenderCupertinoSliverRefresh will paint the child in the available
// space either way but this instructs the _RenderCupertinoSliverRefresh
// on whether to also occupy any layoutExtent space or not.
@ -82,8 +83,8 @@ class _RenderCupertinoSliverRefresh extends RenderSliver
}
// 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
// not.
// way but this determines whether to also occupy any
// [SliverGeometry.layoutExtent] space or not.
bool get hasLayoutExtent => _hasLayoutExtent;
bool _hasLayoutExtent;
set hasLayoutExtent(bool value) {
@ -268,7 +269,7 @@ class CupertinoSliverRefreshControl extends StatefulWidget {
/// Create a new refresh control for inserting into a list of slivers.
///
/// 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
/// shown but the [onRefresh] will still be invoked. By default, [builder]
@ -389,8 +390,8 @@ class CupertinoSliverRefreshControl extends StatefulWidget {
}
class _CupertinoSliverRefreshControlState extends State<CupertinoSliverRefreshControl> {
/// Reset the state from done to inactive when only this fraction of the
/// original `refreshTriggerPullDistance` is left.
// Reset the state from done to inactive when only this fraction of the
// original `refreshTriggerPullDistance` is left.
static const double _inactiveResetOverscrollFraction = 0.1;
RefreshIndicatorMode refreshState;
@ -399,12 +400,12 @@ class _CupertinoSliverRefreshControlState extends State<CupertinoSliverRefreshCo
// 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
// (which partially gets transfered into the layout extent when the refresh
// (which partially gets transferred into the layout extent when the refresh
// 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.
double lastIndicatorExtent = 0.0;
double latestIndicatorBoxExtent = 0.0;
bool hasSliverLayoutExtent = false;
@override
@ -433,7 +434,7 @@ class _CupertinoSliverRefreshControlState extends State<CupertinoSliverRefreshCo
switch (refreshState) {
case RefreshIndicatorMode.inactive:
if (lastIndicatorExtent <= 0) {
if (latestIndicatorBoxExtent <= 0) {
return RefreshIndicatorMode.inactive;
} else {
nextState = RefreshIndicatorMode.drag;
@ -441,9 +442,9 @@ class _CupertinoSliverRefreshControlState extends State<CupertinoSliverRefreshCo
continue drag;
drag:
case RefreshIndicatorMode.drag:
if (lastIndicatorExtent == 0) {
if (latestIndicatorBoxExtent == 0) {
return RefreshIndicatorMode.inactive;
} else if (lastIndicatorExtent < widget.refreshTriggerPullDistance) {
} else if (latestIndicatorBoxExtent < widget.refreshTriggerPullDistance) {
return RefreshIndicatorMode.drag;
} else {
if (widget.onRefresh != null) {
@ -476,7 +477,7 @@ class _CupertinoSliverRefreshControlState extends State<CupertinoSliverRefreshCo
continue done;
}
if (lastIndicatorExtent > widget.refreshIndicatorExtent) {
if (latestIndicatorBoxExtent > widget.refreshIndicatorExtent) {
return RefreshIndicatorMode.armed;
} else {
nextState = RefreshIndicatorMode.refresh;
@ -496,7 +497,7 @@ class _CupertinoSliverRefreshControlState extends State<CupertinoSliverRefreshCo
// 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
// a subsequent pull-to-refresh from starting.
if (lastIndicatorExtent >
if (latestIndicatorBoxExtent >
widget.refreshTriggerPullDistance * _inactiveResetOverscrollFraction) {
return RefreshIndicatorMode.done;
} else {
@ -517,13 +518,13 @@ class _CupertinoSliverRefreshControlState extends State<CupertinoSliverRefreshCo
// its owner to trigger state changes.
child: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
lastIndicatorExtent = constraints.maxHeight;
latestIndicatorBoxExtent = constraints.maxHeight;
refreshState = transitionNextState();
if (widget.builder != null && refreshState != RefreshIndicatorMode.inactive) {
return widget.builder(
context,
refreshState,
lastIndicatorExtent,
latestIndicatorBoxExtent,
widget.refreshTriggerPullDistance,
widget.refreshIndicatorExtent,
);