Skip to content

Commit

Permalink
Merge branch 'main' into fix-swift-package
Browse files Browse the repository at this point in the history
  • Loading branch information
TimOliver committed Mar 18, 2024
2 parents df3e670 + 8213ddb commit 9efb7ff
Show file tree
Hide file tree
Showing 21 changed files with 274 additions and 13 deletions.
1 change: 1 addition & 0 deletions IGListDiffKit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Pod::Spec.new do |s|
s.source_files = 'Source/IGListDiffKit/**/*.{h,m,mm}'
s.private_header_files = 'Source/IGListDiffKit/Internal/*.h'

s.resources = ['Source/PrivacyInfo.xcprivacy']
s.requires_arc = true

s.ios.deployment_target = '11.0'
Expand Down
1 change: 1 addition & 0 deletions IGListKit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Pod::Spec.new do |s|

s.osx.source_files = 'Source/IGListKit/IGListKit.h'

s.resources = ['Source/PrivacyInfo.xcprivacy']
s.requires_arc = true

s.ios.deployment_target = '11.0'
Expand Down
145 changes: 142 additions & 3 deletions IGListKit.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions IGListSwiftKit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Pod::Spec.new do |s|
]
end

s.resources = ['Source/PrivacyInfo.xcprivacy']
s.requires_arc = true

s.swift_versions = ['4.0', '5.0', '5.1']
Expand Down
7 changes: 5 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.0
// swift-tools-version:5.3
import PackageDescription

let package = Package(
Expand All @@ -20,17 +20,20 @@ let package = Package(
name: "IGListDiffKit",
path: "spm/Sources/IGListDiffKit",
publicHeadersPath: "include"
resources: [.copy("PrivacyInfo.xcprivacy")]
),
.target(
name: "IGListKit",
dependencies: ["IGListDiffKit"],
path: "spm/Sources/IGListKit",
publicHeadersPath: "include"
resources: [.copy("PrivacyInfo.xcprivacy")]
),
.target(
name: "IGListSwiftKit",
dependencies: ["IGListKit"],
path: "Source/IGListSwiftKit"
path: "spm/Sources/IGListSwiftKit",
resources: [.copy("PrivacyInfo.xcprivacy")]
),
],
cLanguageStandard: .c11,
Expand Down
4 changes: 3 additions & 1 deletion Source/IGListDiffKit/IGListExperiments.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ typedef NS_OPTIONS (NSInteger, IGListExperiment) {
/// Throw NSInternalInconsistencyException during an update
IGListExperimentThrowOnInconsistencyException = 1 << 3,
/// Test keeping a strong pointer to the collectionView.dataSource during a batch update to avoid a crash
IGListExperimentKeepPointerToCollectionViewDataSource = 1 << 4
IGListExperimentKeepPointerToCollectionViewDataSource = 1 << 4,
/// Test keeping disable all animation on updates
IGListExperimentDisableAnimationOnUpdates= 1 << 5
};

/**
Expand Down
1 change: 1 addition & 0 deletions Source/IGListKit/IGListAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ NS_SWIFT_NAME(ListAdapter)
*/
@property (nonatomic, assign) IGListExperiment experiments;


/**
Initializes a new `IGListAdapter` object.
Expand Down
15 changes: 9 additions & 6 deletions Source/IGListKit/IGListAdapter.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
#import <IGListDiffKit/IGListAssert.h>
#endif
#import "IGListAdapterUpdater.h"
#import "IGListSupplementaryViewSource.h"

#import "IGListArrayUtilsInternal.h"
#import "IGListDebugger.h"
#import "IGListDefaultExperiments.h"
#import "IGListSectionControllerInternal.h"
#import "IGListSupplementaryViewSource.h"
#import "IGListTransitionData.h"
#import "IGListUpdatingDelegate.h"
#import "UICollectionViewLayout+InteractiveReordering.h"
Expand Down Expand Up @@ -64,6 +65,8 @@ - (instancetype)initWithUpdater:(id <IGListUpdatingDelegate>)updater
_updater = updater;
_viewController = viewController;

_experiments = IGListDefaultExperiments();

[IGListDebugger trackAdapter:self];
}
return self;
Expand Down Expand Up @@ -414,7 +417,7 @@ - (void)performUpdatesAnimated:(BOOL)animated completion:(IGListUpdaterCompletio
[strongSelf _updateWithData:data];
}
};

const BOOL shouldAnimateUpdates = animated && !IGListExperimentEnabled(self.experiments, IGListExperimentDisableAnimationOnUpdates);
IGListUpdaterCompletion outerCompletionBlock = ^(BOOL finished){
__typeof__(self) strongSelf = weakSelf;
if (strongSelf == nil) {
Expand All @@ -424,7 +427,7 @@ - (void)performUpdatesAnimated:(BOOL)animated completion:(IGListUpdaterCompletio

// release the previous items
strongSelf.previousSectionMap = nil;
[strongSelf _notifyDidUpdate:IGListAdapterUpdateTypePerformUpdates animated:animated];
[strongSelf _notifyDidUpdate:IGListAdapterUpdateTypePerformUpdates animated:shouldAnimateUpdates];
IGLK_BLOCK_CALL_SAFE(completion,finished);
[strongSelf _exitBatchUpdates];
};
Expand Down Expand Up @@ -686,7 +689,7 @@ - (IGListTransitionData *)_generateTransitionDataWithObjects:(NSArray *)objects
dataSource, object);
return;
}

if ([sectionController isMemberOfClass:[IGListSectionController class]]) {
// If IGListSectionController is not subclassed, it could be a side effect of a problem. For example, nothing stops
// dataSource from returning a plain IGListSectionController if it doesn't recognize the object type, instead of throwing.
Expand Down Expand Up @@ -1367,7 +1370,7 @@ - (void)insertInSectionController:(IGListSectionController *)sectionController a

NSArray *indexPaths = [self indexPathsFromSectionController:sectionController indexes:indexes usePreviousIfInUpdateBlock:NO];
[self.updater insertItemsIntoCollectionView:collectionView indexPaths:indexPaths];

if (![self isInDataUpdateBlock]) {
[self _updateBackgroundView];
}
Expand All @@ -1386,7 +1389,7 @@ - (void)deleteInSectionController:(IGListSectionController *)sectionController a

NSArray *indexPaths = [self indexPathsFromSectionController:sectionController indexes:indexes usePreviousIfInUpdateBlock:YES];
[self.updater deleteItemsFromCollectionView:collectionView indexPaths:indexPaths];

if (![self isInDataUpdateBlock]) {
[self _updateBackgroundView];
}
Expand Down
2 changes: 2 additions & 0 deletions Source/IGListKit/IGListAdapterUpdater.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#endif

#import "IGListAdapterUpdaterHelpers.h"
#import "IGListDefaultExperiments.h"
#import "IGListIndexSetResultInternal.h"
#import "IGListMoveIndexPathInternal.h"
#import "IGListReloadIndexPath.h"
Expand All @@ -37,6 +38,7 @@ - (instancetype)init {
if (self = [super init]) {
_transactionBuilder = [IGListUpdateTransactionBuilder new];
_allowsReloadingOnTooManyUpdates = YES;
_experiments = IGListDefaultExperiments();
}
return self;
}
Expand Down
19 changes: 19 additions & 0 deletions Source/IGListKit/Internal/IGListDefaultExperiments.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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 <Foundation/Foundation.h>

#if __has_include(<IGListDiffKit/IGListDiffKit.h>)
#import <IGListDiffKit/IGListExperiments.h>
#else
#import "IGListExperiments.h"
#endif

/// Provides a list of experiments that are enabled by default in IGListKit.
static inline IGListExperiment IGListDefaultExperiments(void) {
return IGListExperimentThrowOnInconsistencyException;
}
20 changes: 20 additions & 0 deletions Source/PrivacyInfo.xcprivacy
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!--
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.
-->
<plist version="1.0">
<dict>
<key>NSPrivacyAccessedAPITypes</key>
<array/>
<key>NSPrivacyCollectedDataTypes</key>
<array/>
<key>NSPrivacyTracking</key>
<false/>
<key>NSPrivacyTrackingDomains</key>
<array/>
</dict>
</plist>
2 changes: 2 additions & 0 deletions Tests/IGListAdapterE2ETests.m
Original file line number Diff line number Diff line change
Expand Up @@ -2647,6 +2647,8 @@ - (void)test_whenSectionControllerNotSubclassed_thatDoesNotCrash {
// doesn't crash, because it doesn't seem to return attributes where the size is zero.
self.collectionView.collectionViewLayout = [IGListTestCollectionViewLayout new];

XCTExpectFailureWithOptions(@"When IGListSectionController isn't subclassed, expect an assertion failure, but avoid a crash.",
[XCTExpectedFailureOptions nonStrictOptions]);
[self setupWithObjects:@[kIGTestDelegateDataSourceNoSectionControllerSubclass]];

XCTestExpectation *expectation = genExpectation;
Expand Down
61 changes: 60 additions & 1 deletion scripts/generate_spm_sources_layout.sh
Original file line number Diff line number Diff line change
Expand Up @@ -204,19 +204,78 @@ function generate_ig_list_kit() {
generate_ig_list_kit_spm_sources
}

#### IGListSwiftKit
SPM_IG_LIST_SWIFT_KIT_SOURCES_PATH="spm/Sources/IGListSwiftKit"

function generate_ig_list_swift_kit_spm_sources() {
echo "Generate symbolic links for all public implementations. *.swift"
echo "Generated under ${SPM_IG_LIST_SWIFT_KIT_SOURCES_PATH}"

sources_list=$(
find "Source/IGListSwiftKit" \
-type f -name "*.swift" \
-not -path "spm/*" | sed "s| \([^/]\)|:\1|g")

SRC_ROOT=$(pwd)
cd $SPM_IG_LIST_SWIFT_KIT_SOURCES_PATH

for source_file in $sources_list; do
file_to_link=$(echo $source_file | sed "s|:| |g")

ln -s ../../../$file_to_link

done

cd $SRC_ROOT

echo " Done"
echo ""
}

function generate_ig_list_swift_kit() {
generate_ig_list_swift_kit_spm_sources
}

function generate_ig_privacy_manifest_spm() {
echo "Generate symbolic links for privacy manifest"

directories=(${SPM_IG_LIST_KIT_SOURCES_PATH}
${SPM_IG_LIST_DIFF_KIT_SOURCES_PATH}
${SPM_IG_LIST_SWIFT_KIT_SOURCES_PATH})
manifest_file="Source/PrivacyInfo.xcprivacy"
SRC_ROOT=$(pwd)

for directory in ${directories[@]}; do
echo "Generated under ${directory}"
cd ${directory}
file_to_link=$(echo $manifest_file | sed "s|:| |g")
ln -s ../../../$file_to_link
cd $SRC_ROOT
done

echo " Done"
echo ""
}

# Delete all symbolik links from `spm` folder
function cleanup() {
rm -rf $SPM_IG_LIST_DIFF_KIT_PUBLIC_HEADERS_PATH/*.*
rm -rf $SPM_IG_LIST_DIFF_KIT_SOURCES_PATH/*.*
#IGListKit
rm -rf $SPM_IG_LIST_KIT_PUBLIC_HEADERS_PATH/*.*
rm -rf $SPM_IG_LIST_KIT_SOURCES_PATH/*.*
#IGListSwiftKit
rm -rf $SPM_IG_LIST_SWIFT_KIT_SOURCES_PATH/*.*
}

########## SPM generator pipeline #############
#1
cleanup
#2
generate_ig_list_diff_kit
# #3
#3
generate_ig_list_kit
#4
generate_ig_list_swift_kit
#5
generate_ig_privacy_manifest_spm
1 change: 1 addition & 0 deletions spm/Sources/IGListDiffKit/PrivacyInfo.xcprivacy
1 change: 1 addition & 0 deletions spm/Sources/IGListKit/IGListDefaultExperiments.h
1 change: 1 addition & 0 deletions spm/Sources/IGListKit/PrivacyInfo.xcprivacy
1 change: 1 addition & 0 deletions spm/Sources/IGListSwiftKit/ListIdentifiable.swift
1 change: 1 addition & 0 deletions spm/Sources/IGListSwiftKit/PrivacyInfo.xcprivacy

0 comments on commit 9efb7ff

Please sign in to comment.