Skip to content

Commit

Permalink
[MOD] iOS14 availability check. & mapviewRepresentable removed.
Browse files Browse the repository at this point in the history
  • Loading branch information
EnesKaraosman committed Oct 6, 2021
1 parent 4f7745a commit 3cda463
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 116 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Change Log

## [2.0.0](https://github.com/EnesKaraosman/SwiftyChat/releases/tag/2.0.0)
Released on 2021-10-06.

#### Update
- iOS 13 dropped since iOS 15 released.
- Dependency versions upgraded (to 7.0.0) . (Kingfisher)

## [1.3.5](https://github.com/EnesKaraosman/SwiftyChat/releases/tag/1.3.5)
Released on 2021-05-05.

Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import PackageDescription
let package = Package(
name: "SwiftyChat",
platforms: [
.iOS(.v13)
.iOS(.v14)
],
products: [
.library(
Expand Down
51 changes: 4 additions & 47 deletions Sources/SwiftyChat/ChatView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public struct ChatView<Message: ChatMessage, User: ChatUser>: View {
private var onAttributedTextTappedCallback: () -> AttributedTextTappedCallback = { return AttributedTextTappedCallback() }
private var onCarouselItemAction: (CarouselItemButton, Message) -> Void = { (_, _) in }

@available(iOS 14.0, *)
@Binding private var scrollToBottom: Bool
@State private var isKeyboardActive = false

Expand Down Expand Up @@ -55,22 +54,11 @@ public struct ChatView<Message: ChatMessage, User: ChatUser>: View {
}

@ViewBuilder private func chatView(in geometry: GeometryProxy) -> some View {
if #available(iOS 14.0, *) {
iOS14Body(in: geometry.size)
.padding(.bottom, messageEditorHeight + 30)
} else {
iOS14Fallback(in: geometry.size)
.padding(.bottom, messageEditorHeight + 16)
}
}

@available(iOS 14.0, *)
private func iOS14Body(in size: CGSize) -> some View {
ScrollView {
ScrollViewReader { proxy in
LazyVStack {
ForEach(messages) { message in
chatMessageCellContainer(in: size, with: message)
chatMessageCellContainer(in: geometry.size, with: message)
}
}
.onChange(of: scrollToBottom) { value in
Expand Down Expand Up @@ -101,22 +89,7 @@ public struct ChatView<Message: ChatMessage, User: ChatUser>: View {
}
}
.background(Color.clear)
}

private func iOS14Fallback(in size: CGSize) -> some View {
List(messages) { message in
chatMessageCellContainer(in: size, with: message)
}
.onAppear {
// To remove only extra separators below the list:
UITableView.appearance().tableFooterView = UIView()
// To remove all separators including the actual ones:
UITableView.appearance().separatorStyle = .none

// To clear background colors to allow library user set himself
UITableView.appearance().backgroundColor = .clear
UITableViewCell.appearance().backgroundColor = .clear
}
.padding(.bottom, messageEditorHeight + 30)
}

// MARK: - List Item
Expand All @@ -141,36 +114,20 @@ public struct ChatView<Message: ChatMessage, User: ChatUser>: View {

// MARK: - Initializers
public extension ChatView {

/// Initialize
/// - Parameters:
/// - messages: Messages to display
/// - inputView: inputView view to provide message
init(
messages: Binding<[Message]>,
inputView: @escaping () -> AnyView
) {
_messages = messages
self.inputView = inputView
_scrollToBottom = .constant(false)
}

/// iOS 14 initializer, for supporting scrollToBottom
/// ChatView constructor
/// - Parameters:
/// - messages: Messages to display
/// - scrollToBottom: set to `true` to scrollToBottom
/// - inputView: inputView view to provide message
@available(iOS 14.0, *)
init(
messages: Binding<[Message]>,
scrollToBottom: Binding<Bool>,
scrollToBottom: Binding<Bool> = .constant(false),
inputView: @escaping () -> AnyView
) {
_messages = messages
self.inputView = inputView
_scrollToBottom = scrollToBottom
}

}

public extension ChatView {
Expand Down
44 changes: 0 additions & 44 deletions Sources/SwiftyChat/Common/ViewRepresentables/MapView.swift

This file was deleted.

19 changes: 0 additions & 19 deletions Sources/SwiftyChat/MessageCells/LocationCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,6 @@ internal struct LocationCell<Message: ChatMessage>: View {
}

@ViewBuilder private var mapView: some View {
if #available(iOS 14.0, *) {
self.builtInMapView
} else {
self.uiViewRepresentableMapView
}
}

// MARK: - Wrapped Map view (for below iOS 14 versions)
private var uiViewRepresentableMapView: some View {
MapView(
coordinate: CLLocationCoordinate2D(
latitude: location.latitude,
longitude: location.longitude
)
)
}

@available(iOS 14.0, *)
private var builtInMapView: some View {
Map(
coordinateRegion: .constant(
MKCoordinateRegion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@
repositoryURL = "https://github.com/EnesKaraosman/SwiftyChat.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 1.3.1;
minimumVersion = 1.3.6;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"repositoryURL": "https://github.com/onevcat/Kingfisher.git",
"state": {
"branch": null,
"revision": "d06df9adf50ed8cde5786d935836a5f445f780ba",
"version": "6.3.1"
"revision": "8c65ddf756c633d01d9ae01092bf72f0c66dfc60",
"version": "7.0.0"
}
},
{
Expand All @@ -33,8 +33,8 @@
"repositoryURL": "https://github.com/EnesKaraosman/SwiftyChat.git",
"state": {
"branch": null,
"revision": "0add0ccdfd36056943c75af8e626db76e6a9cb89",
"version": "1.3.5"
"revision": "4f7745aed2543a950c184ba2873547e72436a0b3",
"version": "1.3.6"
}
},
{
Expand Down

0 comments on commit 3cda463

Please sign in to comment.