mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-09-16 08:52:04 +00:00
Introduces ASLayoutRangeModeVisibleOnly, allowing the preservation of decoded backing stores without any extra padding to strictly minimize memory usage while supporting immediate re-display of content. Set visible range controllers to this mode upon app suspend / memory warning, while more aggressively clearing others to the ASLayoutRangeModeLowMemory mode. By default, when the app is running and recieves a memory warning, we set the range mode for non-visible controllers to ASLayoutRangeModeVisibleOnly. This is because, unlike in the app suspend case where on app resume we can restore controllers from LowMemory to VisibleOnly, the memory warning doesn't provide a good opportunity to do this. A new +Beta API to control this behavior is called +setRangeModeForMemoryWarnings:, as some apps may prefer to use LowMemory in the memory warning scenario. For these apps, optimal user experience will require manually setting the range mode back to some larger value as the user navigates the app, or they will encounter controllers that are temporarily blank and need a moment to re-display their contents as they start to become visible.
59 lines
2.1 KiB
Objective-C
59 lines
2.1 KiB
Objective-C
/* Copyright (c) 2014-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
|
|
#import "ASLayoutRangeType.h"
|
|
#import "ASViewController.h"
|
|
#import "ASRangeController.h"
|
|
#import "ASCollectionNode.h"
|
|
#import "ASTableNode.h"
|
|
|
|
|
|
@protocol ASRangeControllerUpdateRangeProtocol <NSObject>
|
|
|
|
/**
|
|
* Updates the current range mode of the range controller for at least the next range update.
|
|
*/
|
|
- (void)updateCurrentRangeWithMode:(ASLayoutRangeMode)rangeMode;
|
|
|
|
/**
|
|
* Only ASLayoutRangeModeVisibleOnly or ASLayoutRangeModeLowMemory are recommended. Default is ASLayoutRangeModeVisibleOnly,
|
|
* because this is the only way to ensure an application will not have blank / flashing views as the user navigates back after
|
|
* a memory warning. Apps that wish to use the more effective / aggressive ASLayoutRangeModeLowMemory may need to take steps
|
|
* to mitigate this behavior, including: restoring a larger range mode to the next controller before the user navigates there,
|
|
* enabling .neverShowPlaceholders on ASCellNodes so that the navigation operation is blocked on redisplay completing, etc.
|
|
*/
|
|
+ (void)setRangeModeForMemoryWarnings:(ASLayoutRangeMode)rangeMode;
|
|
|
|
@end
|
|
|
|
|
|
@interface ASRangeController (ASRangeControllerUpdateRangeProtocol) <ASRangeControllerUpdateRangeProtocol>
|
|
|
|
/// This is a way for a one way update of range with a given mode.
|
|
- (void)updateCurrentRangeWithMode:(ASLayoutRangeMode)rangeMode;
|
|
|
|
@end
|
|
|
|
|
|
@interface ASCollectionNode (ASRangeControllerUpdateRangeProtocol) <ASRangeControllerUpdateRangeProtocol>
|
|
|
|
@end
|
|
|
|
|
|
@interface ASTableNode (ASRangeControllerUpdateRangeProtocol) <ASRangeControllerUpdateRangeProtocol>
|
|
|
|
@end
|
|
|
|
|
|
@interface ASViewController (ASRangeControllerUpdateRangeProtocol)
|
|
|
|
/// Automatically adjust range mode based on view evenets if the containing node confirms to the ASRangeControllerUpdateRangeProtocol
|
|
@property (nonatomic, assign) BOOL automaticallyAdjustRangeModeBasedOnViewEvents;
|
|
|
|
@end
|