Skip to content

Commit ec18c34

Browse files
Embedding third-party dependencies (#379)
1 parent 40a5c07 commit ec18c34

File tree

114 files changed

+13388
-47
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+13388
-47
lines changed

.github/workflows/cron-checks.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ jobs:
107107
if: failure()
108108
run: |
109109
brew install chargepoint/xcparse/xcparse
110-
xcparse logs fastlane/test_output/StreamChatUITestsApp.xcresult fastlane/test_output/logs/
110+
xcparse logs fastlane/test_output/StreamChatSwiftUITestsApp.xcresult fastlane/test_output/logs/
111111
- uses: actions/upload-artifact@v3
112112
if: failure()
113113
with:

.github/workflows/smoke-checks.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ jobs:
152152
if: failure()
153153
run: |
154154
brew install chargepoint/xcparse/xcparse
155-
xcparse logs fastlane/test_output/StreamChatUITestsApp.xcresult fastlane/test_output/logs/
155+
xcparse logs fastlane/test_output/StreamChatSwiftUITestsApp.xcresult fastlane/test_output/logs/
156156
- uses: actions/upload-artifact@v3
157157
if: failure()
158158
with:

.slather.yml

+2
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ ignore:
1010
- "**/*_Mock.swift"
1111
- "**/*_Vendor.swift"
1212
- "**/Generated/*.swift"
13+
- "Sources/StreamChatSwiftUI/StreamNuke"
14+
- "Sources/StreamChatSwiftUI/StreamSwiftyGif"

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
33

44
# Upcoming
55

6+
### ⚠️ Important
7+
8+
- Dependencies are no longer exposed (this includes Nuke and SwiftyGif). If you were using those dependencies we were exposing, you would need to import them manually. If you encounter any SPM-related problems, be sure to reset the package caches.
9+
610
### ✅ Added
711
- Add message preview with attachments in channel list
812

DemoAppSwiftUI/AppDelegate.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,20 @@ class AppDelegate: NSObject, UIApplicationDelegate {
6868
streamChat = StreamChat(chatClient: chatClient, utils: utils)
6969

7070
let credentials = UnsecureRepository.shared.loadCurrentUser()
71-
if let credentials, let token = try? Token(rawValue: credentials.token) {
71+
if let credentials, let token = try? Token(rawValue: credentials.token) {
7272
chatClient.connectUser(
7373
userInfo: .init(
7474
id: credentials.id,
7575
name: credentials.name,
7676
imageURL: credentials.avatarURL
7777
),
78-
token: token
78+
token: token
7979
)
8080
}
8181

8282
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
8383
withAnimation {
84-
if AppState.shared.userState == .launchAnimation {
84+
if AppState.shared.userState == .launchAnimation {
8585
AppState.shared.userState = credentials == nil ? .notLoggedIn : .loggedIn
8686
}
8787
}

DemoAppSwiftUI/UserRepository.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Copyright © 2023 Stream.io Inc. All rights reserved.
33
//
44

5-
import StreamChat
65
import Foundation
6+
import StreamChat
77

88
protocol UserRepository {
99

@@ -14,7 +14,7 @@ protocol UserRepository {
1414
func removeCurrentUser()
1515
}
1616

17-
//NOTE: This is just for simplicity. User data shouldn't be kept in `UserDefaults`.
17+
// NOTE: This is just for simplicity. User data shouldn't be kept in `UserDefaults`.
1818
final class UnsecureRepository: UserRepository {
1919
enum Key: String, CaseIterable {
2020
case user = "stream.chat.user"

Makefile

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MAKEFLAGS += --silent
2+
3+
update_dependencies:
4+
echo "👉 Updating Nuke"
5+
make update_nuke version=11.3.1
6+
echo "👉 Updating SwiftyGif"
7+
make update_swiftygif version=5.4.2
8+
9+
update_nuke: check_version_parameter
10+
./Scripts/updateDependency.sh $(version) Dependencies/Nuke Sources/StreamChatSwiftUI/StreamNuke Sources
11+
./Scripts/removePublicDeclarations.sh Sources/StreamChatSwiftUI/StreamNuke
12+
13+
update_swiftygif: check_version_parameter
14+
./Scripts/updateDependency.sh $(version) Dependencies/SwiftyGif Sources/StreamChatSwiftUI/StreamSwiftyGif SwiftyGif
15+
./Scripts/removePublicDeclarations.sh Sources/StreamChatSwiftUI/StreamSwiftyGif
16+
17+
check_version_parameter:
18+
@if [ "$(version)" = "" ]; then\
19+
echo "❌ Missing version parameter"; \
20+
exit 1;\
21+
fi

Package.swift

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ let package = Package(
1717
)
1818
],
1919
dependencies: [
20-
.package(url: "https://github.com/GetStream/stream-chat-swift.git", from: "4.39.0"),
21-
.package(url: "https://github.com/kean/Nuke.git", .exact("11.3.1"))
20+
.package(url: "https://github.com/GetStream/stream-chat-swift.git", from: "4.39.0"),
2221
],
2322
targets: [
2423
.target(
2524
name: "StreamChatSwiftUI",
26-
dependencies: [.product(name: "StreamChat", package: "stream-chat-swift"), "Nuke", .product(name: "NukeUI", package: "Nuke")],
25+
dependencies: [.product(name: "StreamChat", package: "stream-chat-swift")],
2726
exclude: ["README.md", "Info.plist", "Generated/L10n_template.stencil"],
2827
resources: [.process("Resources")]
2928
)

Scripts/removePublicDeclarations.sh

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Usage: ./removePublicDeclarations.sh Sources/StreamNuke
4+
#
5+
# This script would iterate over the files on a particular directory, and perform basic replacement operations.
6+
# It heavily relies on 'sed':
7+
# sed -i '<backup-file-extension>' -e 's/<original-string>/<replacement>/g' <file>
8+
# ^
9+
# Passing empty string prevents the creation of backup files
10+
11+
args=("$@")
12+
directory=$1
13+
14+
replaceDeclaration() {
15+
original=$1
16+
replacement=$2
17+
file=$3
18+
`sed -i '' -e "s/$original/$replacement/g" $file`
19+
}
20+
21+
files=`find $directory -name "*.swift"`
22+
for f in $files
23+
do
24+
replaceDeclaration 'public internal(set) ' '' $f
25+
replaceDeclaration 'open ' '' $f
26+
replaceDeclaration 'public ' '' $f
27+
28+
# Nuke
29+
if [[ $directory == *"Nuke"* ]]; then
30+
replaceDeclaration 'var log' 'var nukeLog' $f
31+
replaceDeclaration 'log =' 'nukeLog =' $f
32+
replaceDeclaration 'log: log' 'log: nukeLog' $f
33+
replaceDeclaration 'signpost(log' 'signpost(nukeLog' $f
34+
replaceDeclaration ' Cache(' ' NukeCache(' $f
35+
replaceDeclaration ' Cache<' ' NukeCache<' $f
36+
replaceDeclaration ' Image?' ' NukeImage?' $f
37+
replaceDeclaration ' Image(' ' NukeImage(' $f
38+
replaceDeclaration 'struct Image:' 'struct NukeImage:' $f
39+
replaceDeclaration 'extension Image {' 'extension NukeImage {' $f
40+
replaceDeclaration 'Content == Image' 'Content == NukeImage' $f
41+
replaceDeclaration ' VideoPlayerView' ' NukeVideoPlayerView' $f
42+
replaceDeclaration 'typealias Color' 'typealias NukeColor' $f
43+
replaceDeclaration 'extension Color' 'extension NukeColor' $f
44+
replaceDeclaration 'AssetType' 'NukeAssetType' $f
45+
replaceDeclaration 'typealias ImageRequest = Nuke.ImageRequest' '' $f
46+
replaceDeclaration 'typealias ImageResponse = Nuke.ImageResponse' '' $f
47+
replaceDeclaration 'typealias ImagePipeline = Nuke.ImagePipeline' '' $f
48+
replaceDeclaration 'typealias ImageContainer = Nuke.ImageContainer' '' $f
49+
replaceDeclaration 'open class ' '' $f
50+
replaceDeclaration 'import Nuke' '' $f
51+
52+
# Remove Cancellable interface duplicate
53+
if [[ $f == *"DataLoader"* && `head -10 $f` == *"protocol Cancellable"* ]]; then
54+
`sed -i '' -e '7,11d' $f`
55+
fi
56+
57+
# Rename files
58+
if [[ $f == *"Caching/Cache.swift" ]]; then
59+
new_f="${f/Cache.swift/NukeCache.swift}"
60+
mv "$f" "$new_f"
61+
elif [[ $f == *"NukeUI/VideoPlayerView.swift" ]]; then
62+
new_f="${f/VideoPlayerView.swift/NukeVideoPlayerView.swift}"
63+
mv "$f" "$new_f"
64+
fi
65+
fi
66+
done

Scripts/removeUnneededSymbols.sh

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Usage: ./removeUnneededSymbols.sh StreamChatSwiftUI ./Products
4+
#
5+
# Creating an xcframework for StreamChatSwiftUI generates a .bcsymbolmap file for itself, and one for
6+
# each of its dependencies too (eg. StreamChat). That means that we will end up having something like:
7+
#
8+
# -> StreamChatSwiftUI/BCSymbolMaps/
9+
# <UUID-StreamChatSwiftUI>.bcsymbolmap
10+
# <UUID-StreamChat>.bcsymbolmap
11+
#
12+
# When adding both StreamChat and StreamChatSwiftUI to an app, it will throw an error when trying to compile
13+
# saying that there are multiple executions producing the same file (<UUID-StreamChat>.bcsymbolmap).
14+
#
15+
# This script will remove duplicated .bcsymbolmap in the generated xcframeworks.
16+
# If we countinue with the same example, it will leave it as follows:
17+
#
18+
# -> StreamChatSwiftUI/BCSymbolMaps/
19+
# <UUID-StreamChatSwiftUI>.bcsymbolmap
20+
#
21+
# Each xcframework only contains its symbols now.
22+
23+
args=("$@")
24+
library=$1
25+
output_directory=$2
26+
27+
function removeUnneededSymbols() {
28+
arch=$1
29+
path="$output_directory/$library.xcframework/$arch/BCSymbolMaps"
30+
cd $path
31+
32+
# Looking for [...]/DerivedSources/[LIBRARY-NAME]_vers.c
33+
regex="(\/DerivedSources\/)([a-zA-Z_]*)(_vers.c)"
34+
files="*.bcsymbolmap"
35+
for f in $files
36+
do
37+
text=`head -10 $f`
38+
[[ $text =~ $regex ]]
39+
library_match="${BASH_REMATCH[2]}"
40+
if [[ $library_match != $library ]]
41+
then
42+
echo "→ Removing uneeded 'bcsymbolmap' from $library-$arch: $library_match - $f"
43+
rm $f
44+
fi
45+
done
46+
47+
cd - >/dev/null
48+
}
49+
50+
removeUnneededSymbols "ios-arm64"
51+
removeUnneededSymbols "ios-arm64_x86_64-simulator"

Scripts/run-linter.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -euo pipefail
44
echo -e "👉 Running SwiftFormat Linting"
55

66
echo -e "👉 Linting Sources..."
7-
mint run swiftformat --lint --config .swiftformat Sources --exclude **/Generated
7+
mint run swiftformat --lint --config .swiftformat Sources --exclude **/Generated,Sources/StreamChatSwiftUI/StreamNuke,Sources/StreamChatSwiftUI/StreamSwiftyGif
88
echo -e "👉 Linting Tests..."
99
mint run swiftformat --lint --config .swiftformat StreamChatSwiftUITests
1010
echo -e "👉 Linting DemoApp..."

Scripts/updateDependency.sh

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Usage: ./updateDependency.sh 10.3.3 Dependencies/Nuke Sources/StreamNuke Sources
4+
#
5+
# This script gets the source code of a dependency of a given library, and copies it to our codebase
6+
7+
ensure_clean_git () {
8+
if !(git diff-index --quiet HEAD)
9+
then
10+
echo "→ Seems like git is not clean in $dependency_directory. Please make sure it is clean, and run it again"
11+
exit 1
12+
fi
13+
}
14+
15+
args=("$@")
16+
version=$1
17+
dependency_directory=$2
18+
output_directory=$3
19+
sources_directory=$4
20+
21+
dependency_url=""
22+
23+
if [[ $dependency_directory == *"Nuke"* ]]; then
24+
dependency_url="[email protected]:kean/Nuke.git"
25+
elif [[ $dependency_directory == *"SwiftyGif"* ]]; then
26+
dependency_url="[email protected]:kirualex/SwiftyGif.git"
27+
else
28+
echo "→ Unknown dependency at $dependency_directory"
29+
exit 1
30+
fi
31+
32+
if ! [[ -d "$dependency_directory" ]]; then
33+
echo "$dependency_directory does not exist in your filesystem. Cloning the repo"
34+
git clone $dependency_url $dependency_directory
35+
fi
36+
37+
cd $dependency_directory
38+
39+
ensure_clean_git
40+
41+
git fetch --tags
42+
git checkout $version
43+
44+
ensure_clean_git
45+
46+
cd -
47+
48+
echo "→ Copying source files"
49+
rm -rf $output_directory
50+
mkdir $output_directory
51+
cp -r "$dependency_directory/$sources_directory/." $output_directory
52+
53+
54+
for f in `find $output_directory -type f \( -iname \*.h -o -iname \*.plist \)`
55+
do
56+
echo "→ Removing $f"
57+
rm $f
58+
done
59+
60+
rm -rf $dependency_directory

Sources/StreamChatSwiftUI/ChatChannel/ChatChannelViewModel.swift

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//
44

55
import Combine
6-
import Nuke
76
import StreamChat
87
import SwiftUI
98

@@ -163,7 +162,7 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
163162

164163
@objc
165164
private func didReceiveMemoryWarning() {
166-
Nuke.ImageCache.shared.removeAll()
165+
ImageCache.shared.removeAll()
167166
messageCachingUtils.clearCache()
168167
}
169168

@@ -511,7 +510,7 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
511510
messageCachingUtils.clearCache()
512511
if messageController == nil {
513512
utils.channelControllerFactory.clearCurrentController()
514-
Nuke.ImageCache.shared.trim(toCost: utils.messageListConfig.cacheSizeOnChatDismiss)
513+
ImageCache.shared.trim(toCost: utils.messageListConfig.cacheSizeOnChatDismiss)
515514
}
516515
}
517516
}

Sources/StreamChatSwiftUI/ChatChannel/Gallery/ZoomableScrollView.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ private struct ZoomableScrollViewImpl<Content: View>: UIViewControllerRepresenta
5050
let coordinator: Coordinator
5151
let scrollView = UIScrollView()
5252

53-
var doubleTapCancellable: Cancellable?
54-
var updateConstraintsCancellable: Cancellable?
53+
var doubleTapCancellable: Combine.Cancellable?
54+
var updateConstraintsCancellable: Combine.Cancellable?
5555

5656
private var hostedView: UIView { coordinator.hostingController.view! }
5757

Sources/StreamChatSwiftUI/ChatChannel/MessageList/GiphyAttachmentView.swift

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Copyright © 2023 Stream.io Inc. All rights reserved.
33
//
44

5-
import Nuke
6-
import NukeUI
75
import StreamChat
86
import SwiftUI
97

@@ -106,7 +104,7 @@ struct LazyGiphyView: View {
106104
var body: some View {
107105
LazyImage(imageURL: source) { state in
108106
if let imageContainer = state.imageContainer {
109-
Image(imageContainer)
107+
NukeImage(imageContainer)
110108
} else if state.error != nil {
111109
Color(.secondarySystemBackground)
112110
} else {

Sources/StreamChatSwiftUI/ChatChannel/MessageList/ImageAttachmentView.swift

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Copyright © 2023 Stream.io Inc. All rights reserved.
33
//
44

5-
import Nuke
6-
import NukeUI
75
import StreamChat
86
import SwiftUI
97

Sources/StreamChatSwiftUI/ChatChannel/MessageList/LinkAttachmentView.swift

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Copyright © 2023 Stream.io Inc. All rights reserved.
33
//
44

5-
import Nuke
6-
import NukeUI
75
import StreamChat
86
import SwiftUI
97

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageAvatarView.swift

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Copyright © 2023 Stream.io Inc. All rights reserved.
33
//
44

5-
import NukeUI
65
import StreamChat
76
import SwiftUI
87

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageContainerView.swift

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
//
44

55
import AVKit
6-
import Nuke
7-
import NukeUI
86
import StreamChat
97
import SwiftUI
108

0 commit comments

Comments
 (0)