diff --git a/Source/IGListKit/IGListAdapter.h b/Source/IGListKit/IGListAdapter.h index 1e00d190e..dcf50f469 100644 --- a/Source/IGListKit/IGListAdapter.h +++ b/Source/IGListKit/IGListAdapter.h @@ -143,7 +143,7 @@ NS_SWIFT_NAME(ListAdapter) @param animated A flag indicating if the transition should be animated. @param completion The block to execute when the updates complete. */ -- (void)performUpdatesAnimated:(BOOL)animated completion:(nullable IGListUpdaterCompletion)completion; +- (void)performUpdatesAnimated:(BOOL)animated completion:(nullable IGListUpdaterCompletion)completion NS_SWIFT_DISABLE_ASYNC; /** Perform an immediate reload of the data in the data source, discarding the old objects. @@ -153,7 +153,7 @@ NS_SWIFT_NAME(ListAdapter) @warning Do not use this method to update without animations as it can be very expensive to teardown and rebuild all section controllers. Use `-[IGListAdapter performUpdatesAnimated:completion]` instead. */ -- (void)reloadDataWithCompletion:(nullable IGListUpdaterCompletion)completion; +- (void)reloadDataWithCompletion:(nullable IGListUpdaterCompletion)completion NS_SWIFT_DISABLE_ASYNC; /** Reload the list for only the specified objects. diff --git a/Source/IGListSwiftKit/IGListAdapter+Async.swift b/Source/IGListSwiftKit/IGListAdapter+Async.swift new file mode 100644 index 000000000..c1a4b2888 --- /dev/null +++ b/Source/IGListSwiftKit/IGListAdapter+Async.swift @@ -0,0 +1,39 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import IGListKit + +public extension ListAdapter { + /// Perform an update from the previous state of the data source. This is analogous to calling + /// `UICollectionView.performBatchUpdates(_:completion:)`. + /// + /// - Parameter animated: A flag indicating if the transition should be animated. + /// - Returns: `true` if the update animations completed successfully; otherwise `false`. + @discardableResult + func performUpdates(animated: Bool) async -> Bool { + return await withCheckedContinuation { continuation in + performUpdates(animated: animated) { finished in + continuation.resume(returning: finished) + } + } + } + + /// Perform an immediate reload of the data in the data source, discarding the old objects. + /// + /// - Returns: `true` if the update animations completed successfully; otherwise `false`. + /// + /// @warning Do not use this method to update without animations as it can be very expensive to teardown and rebuild all + /// section controllers. Use `performUpdates(animated:) async` instead. + @discardableResult + func reloadData() async -> Bool { + return await withCheckedContinuation { continuation in + reloadData { finished in + continuation.resume(returning: finished) + } + } + } +}