beginActivity method
Change the current activity, disposing of the old one and sending scroll notifications as necessary.
If the argument is null, this method has no effect. This is convenient for cases where the new activity is obtained from another method, and that method might return null, since it means the caller does not have to explicitly null-check the argument.
Implementation
@override
void beginActivity(ScrollActivity? newActivity) {
int oldSetPixels = 0;
void before(MTDriveIndicator indicator) {
// assert(() {
// bool isOk = true;
// if (!indicator.activityHasInit) {
// isOk = activity == null;
// } else {
// isOk = newActivity != null;
// }
// indicator.activityHasInit = true;
// if(!isOk){
// print("err");
// }
// return isOk;
// }());
}
final oldActivity = activity;
mtLog(
"beginActivity - OLD: ${oldActivity?.runtimeType} hash:${oldActivity?.hashCode} 速度:${oldActivity?.velocity} \n \t --- NEW:${newActivity?.runtimeType} ${newActivity?.hashCode} 速度:${newActivity?.velocity} ${FrameUtil.debugFrameCount}",
tag: TagsConfig.tagActivity);
oldSetPixels = _debugSetPixels;
final headerIndicator = coordinator.headerIndicator;
if (headerIndicator != null) {
before(headerIndicator);
}
final footerIndicator = coordinator.footerIndicator;
if (footerIndicator != null) {
before(footerIndicator);
}
super.beginActivity(newActivity);
void after(MTDriveIndicator indicator) {
assert(oldSetPixels == _debugSetPixels,
"说明在beginActivity中修改了pixels,要重新考虑逻辑!调查这个非常重要,表明即使是惯性滚动,也是下一帧才会执行的,这样依赖我们将MTIndicator.currentActivity放在真正改变activity调用之前或者之后,效果是一样的,不会出现副作用,因为这个方法执行过程中不会对pixel进行任何修改。同时也会有潜在的因素,比如已经强制修改过pixels了,但是下一帧还是会修改pixels。造成跳动");
/// 必须放在activity改变之后,因为实际是否更改还是需要确认的,放在super之前则可能造成不一致
/// 放前放后都不行,都无法处理好拖拽时候goIdle的问题
/// 如果我只给idle和动画阶段才通知更改acticity呢?
// if (WidgetsBinding.instance.schedulerPhase == SchedulerPhase.idle || WidgetsBinding.instance.schedulerPhase == SchedulerPhase.transientCallbacks) {
// indicator.changeCurrentActivity(activity);
// }
}
if (headerIndicator != null) {
after(headerIndicator);
}
if (footerIndicator != null) {
after(footerIndicator);
}
}