Skip to content

Commit

Permalink
Add live location status view in the snapshot view
Browse files Browse the repository at this point in the history
  • Loading branch information
nuno-vieira committed Jan 3, 2025
1 parent 533e331 commit 2f4a35a
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright © 2024 Stream.io Inc. All rights reserved.
// Copyright © 2025 Stream.io Inc. All rights reserved.
//

import CoreLocation
Expand All @@ -15,15 +15,6 @@ class DemoComposerVC: ComposerVC {

let alreadyHasLocation = content.attachments.map(\.type).contains(.staticLocation)
if AppConfig.shared.demoAppConfig.isLocationAttachmentsEnabled && !alreadyHasLocation {
let addLocationAction = UIAlertAction(
title: "Add Current Location",
style: .default,
handler: { [weak self] _ in
self?.addStaticLocationToAttachments()
}
)
actions.append(addLocationAction)

let sendLocationAction = UIAlertAction(
title: "Send Current Location",
style: .default,
Expand All @@ -46,17 +37,6 @@ class DemoComposerVC: ComposerVC {
return actions
}

func addStaticLocationToAttachments() {
getCurrentLocationInfo { [weak self] location in
guard let location = location else { return }
let staticLocationPayload = StaticLocationAttachmentPayload(
latitude: location.latitude,
longitude: location.longitude
)
self?.content.attachments.append(AnyAttachmentPayload(payload: staticLocationPayload))
}
}

func sendInstantStaticLocation() {
getCurrentLocationInfo { [weak self] location in
guard let location = location else { return }
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ class LocationAttachmentSnapshotView: _View, ThemeProvider {
return view
}()

lazy var sharingStatusView: LocationSharingStatusView = {
let view = LocationSharingStatusView()
view.translatesAutoresizingMaskIntoConstraints = false
view.isHidden = true
return view
}()

override func setUp() {
super.setUp()

Expand All @@ -94,6 +101,12 @@ class LocationAttachmentSnapshotView: _View, ThemeProvider {
imageView.addGestureRecognizer(tapGestureRecognizer)
}

override func setUpAppearance() {
super.setUpAppearance()

backgroundColor = appearance.colorPalette.background6
}

override func setUpLayout() {
super.setUpLayout()

Expand All @@ -102,9 +115,11 @@ class LocationAttachmentSnapshotView: _View, ThemeProvider {

addSubview(activityIndicatorView)

let container = VContainer(alignment: .center) {
let container = VContainer(spacing: 0, alignment: .center) {
imageView
.height(mapHeight)
sharingStatusView
.height(30)
stopButton
.width(120)
.height(35)
Expand All @@ -113,9 +128,10 @@ class LocationAttachmentSnapshotView: _View, ThemeProvider {
addSubview(avatarView)

NSLayoutConstraint.activate([
activityIndicatorView.centerXAnchor.constraint(equalTo: imageView.centerXAnchor),
activityIndicatorView.centerYAnchor.constraint(equalTo: imageView.centerYAnchor),
activityIndicatorView.centerXAnchor.constraint(equalTo: centerXAnchor),
activityIndicatorView.centerYAnchor.constraint(equalTo: centerYAnchor),
imageView.widthAnchor.constraint(equalTo: container.widthAnchor),

avatarView.centerXAnchor.constraint(equalTo: imageView.centerXAnchor),
avatarView.centerYAnchor.constraint(equalTo: imageView.centerYAnchor),
avatarView.widthAnchor.constraint(equalToConstant: 30),
Expand All @@ -136,8 +152,15 @@ class LocationAttachmentSnapshotView: _View, ThemeProvider {

if content.isSharingLiveLocation && content.isFromCurrentUser {
stopButton.isHidden = false
sharingStatusView.isHidden = true
sharingStatusView.updateStatus(isSharing: true)
} else if content.isLive {
stopButton.isHidden = true
sharingStatusView.isHidden = false
sharingStatusView.updateStatus(isSharing: content.isSharingLiveLocation)
} else {
stopButton.isHidden = true
sharingStatusView.isHidden = true
}

configureMapPosition()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ class LocationAttachmentViewInjector: AttachmentViewInjector {
locationAttachmentView.didTapOnStopSharingLocation = { [weak self] in
self?.handleTapOnStopSharingLocation()
}

let isSentByCurrentUser = contentView.content?.isSentByCurrentUser == true
let maskedCorners: CACornerMask = isSentByCurrentUser
? [.layerMinXMaxYCorner, .layerMinXMinYCorner]
: [.layerMinXMinYCorner, .layerMaxXMaxYCorner, .layerMaxXMinYCorner]
locationAttachmentView.layer.maskedCorners = maskedCorners
locationAttachmentView.layer.cornerRadius = 16
locationAttachmentView.layer.masksToBounds = true
}

override func contentViewDidUpdateContent() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// Copyright © 2025 Stream.io Inc. All rights reserved.
//

import StreamChat
import StreamChatUI
import UIKit

class LocationSharingStatusView: _View, ThemeProvider {
private lazy var statusLabel: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.font = appearance.fonts.footnote
label.textColor = appearance.colorPalette.subtitleText
return label
}()

private var activeSharingImage: UIImage? = UIImage(
systemName: "location.fill",
withConfiguration: UIImage.SymbolConfiguration(scale: .medium)
)

private var inactiveSharingImage: UIImage? = UIImage(
systemName: "location.slash.fill",
withConfiguration: UIImage.SymbolConfiguration(scale: .medium)
)

private lazy var iconImageView: UIImageView = {
let imageView = UIImageView()
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.contentMode = .scaleAspectFit
imageView.image = activeSharingImage
return imageView
}()

override func setUpLayout() {
super.setUpLayout()

let container = HContainer(spacing: 4, alignment: .center) {
iconImageView
.width(16)
.height(16)
statusLabel
}.embed(in: self)
}

func updateStatus(isSharing: Bool) {
statusLabel.text = isSharing ? "Live location active" : "Live location ended"
iconImageView.image = isSharing ? activeSharingImage : inactiveSharingImage
iconImageView.tintColor = isSharing
? appearance.colorPalette.accentPrimary
: appearance.colorPalette.subtitleText
}
}
8 changes: 4 additions & 4 deletions StreamChat.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,6 @@
AD053B9A2B335854003612B6 /* DemoComposerVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD053B992B335854003612B6 /* DemoComposerVC.swift */; };
AD053B9F2B335929003612B6 /* LocationAttachmentViewInjector.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD053B9E2B335929003612B6 /* LocationAttachmentViewInjector.swift */; };
AD053BA12B3359DD003612B6 /* DemoAttachmentViewCatalog.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD053BA02B3359DD003612B6 /* DemoAttachmentViewCatalog.swift */; };
AD053BA32B335A13003612B6 /* LocationAttachmentPayload+AttachmentViewProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD053BA22B335A13003612B6 /* LocationAttachmentPayload+AttachmentViewProvider.swift */; };
AD053BA52B335A63003612B6 /* DemoQuotedChatMessageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD053BA42B335A63003612B6 /* DemoQuotedChatMessageView.swift */; };
AD053BA72B33624C003612B6 /* LocationAttachmentViewDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD053BA62B33624C003612B6 /* LocationAttachmentViewDelegate.swift */; };
AD053BA92B336331003612B6 /* LocationDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD053BA82B336331003612B6 /* LocationDetailViewController.swift */; };
Expand Down Expand Up @@ -1466,6 +1465,7 @@
AD470C9E26C6D9030090759A /* ChatMessageListVCDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD470C9D26C6D9030090759A /* ChatMessageListVCDelegate.swift */; };
AD483B962A2658970004B406 /* ChannelMemberUnbanRequestPayload.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD483B952A2658970004B406 /* ChannelMemberUnbanRequestPayload.swift */; };
AD483B972A2658970004B406 /* ChannelMemberUnbanRequestPayload.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD483B952A2658970004B406 /* ChannelMemberUnbanRequestPayload.swift */; };
AD48F6922D2849B5007CCF3A /* LocationSharingStatusView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD48F6912D2849B5007CCF3A /* LocationSharingStatusView.swift */; };
AD4C15562A55874700A32955 /* ImageLoading_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD4C15552A55874700A32955 /* ImageLoading_Tests.swift */; };
AD4C8C222C5D479B00E1C414 /* StackedUserAvatarsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD4C8C212C5D479B00E1C414 /* StackedUserAvatarsView.swift */; };
AD4C8C232C5D479B00E1C414 /* StackedUserAvatarsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD4C8C212C5D479B00E1C414 /* StackedUserAvatarsView.swift */; };
Expand Down Expand Up @@ -4164,7 +4164,6 @@
AD053B992B335854003612B6 /* DemoComposerVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoComposerVC.swift; sourceTree = "<group>"; };
AD053B9E2B335929003612B6 /* LocationAttachmentViewInjector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationAttachmentViewInjector.swift; sourceTree = "<group>"; };
AD053BA02B3359DD003612B6 /* DemoAttachmentViewCatalog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoAttachmentViewCatalog.swift; sourceTree = "<group>"; };
AD053BA22B335A13003612B6 /* LocationAttachmentPayload+AttachmentViewProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "LocationAttachmentPayload+AttachmentViewProvider.swift"; sourceTree = "<group>"; };
AD053BA42B335A63003612B6 /* DemoQuotedChatMessageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoQuotedChatMessageView.swift; sourceTree = "<group>"; };
AD053BA62B33624C003612B6 /* LocationAttachmentViewDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationAttachmentViewDelegate.swift; sourceTree = "<group>"; };
AD053BA82B336331003612B6 /* LocationDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationDetailViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4236,6 +4235,7 @@
AD470C9B26C6D8C60090759A /* ChatMessageListVCDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatMessageListVCDataSource.swift; sourceTree = "<group>"; };
AD470C9D26C6D9030090759A /* ChatMessageListVCDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatMessageListVCDelegate.swift; sourceTree = "<group>"; };
AD483B952A2658970004B406 /* ChannelMemberUnbanRequestPayload.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChannelMemberUnbanRequestPayload.swift; sourceTree = "<group>"; };
AD48F6912D2849B5007CCF3A /* LocationSharingStatusView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationSharingStatusView.swift; sourceTree = "<group>"; };
AD4C15552A55874700A32955 /* ImageLoading_Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageLoading_Tests.swift; sourceTree = "<group>"; };
AD4C8C212C5D479B00E1C414 /* StackedUserAvatarsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StackedUserAvatarsView.swift; sourceTree = "<group>"; };
AD4CDD81296498D20057BC8A /* ScrollViewPaginationHandler_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrollViewPaginationHandler_Tests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -8389,11 +8389,11 @@
AD053B9B2B33589C003612B6 /* LocationAttachment */ = {
isa = PBXGroup;
children = (
AD053BA22B335A13003612B6 /* LocationAttachmentPayload+AttachmentViewProvider.swift */,
AD053B9E2B335929003612B6 /* LocationAttachmentViewInjector.swift */,
AD053BA62B33624C003612B6 /* LocationAttachmentViewDelegate.swift */,
AD053BAA2B33638B003612B6 /* LocationAttachmentSnapshotView.swift */,
AD053BA82B336331003612B6 /* LocationDetailViewController.swift */,
AD48F6912D2849B5007CCF3A /* LocationSharingStatusView.swift */,
AD2F2D9A2D271B36006ED24B /* UserAnnotationView.swift */,
AD2F2D982D271B07006ED24B /* UserAnnotation.swift */,
);
Expand Down Expand Up @@ -11062,6 +11062,7 @@
794E20F52577DF4D00790DAB /* NameGroupViewController.swift in Sources */,
A3227EC9284A52EE00EBE6CC /* PushNotifications.swift in Sources */,
A3227E65284A4A5C00EBE6CC /* StreamChatWrapper.swift in Sources */,
AD48F6922D2849B5007CCF3A /* LocationSharingStatusView.swift in Sources */,
A3227E78284A4CAD00EBE6CC /* DemoChatMessageContentView.swift in Sources */,
AD2F2D992D271B07006ED24B /* UserAnnotation.swift in Sources */,
7933060B256FF94800FBB586 /* DemoChatChannelListRouter.swift in Sources */,
Expand All @@ -11076,7 +11077,6 @@
AD2F2D9B2D271B36006ED24B /* UserAnnotationView.swift in Sources */,
A3227E59284A484300EBE6CC /* UIImage+Resized.swift in Sources */,
79B8B64B285CBDC00059FB2D /* DemoChatMessageLayoutOptionsResolver.swift in Sources */,
AD053BA32B335A13003612B6 /* LocationAttachmentPayload+AttachmentViewProvider.swift in Sources */,
AD053BA12B3359DD003612B6 /* DemoAttachmentViewCatalog.swift in Sources */,
AD053B9F2B335929003612B6 /* LocationAttachmentViewInjector.swift in Sources */,
);
Expand Down

0 comments on commit 2f4a35a

Please sign in to comment.