Skip to content

Commit 8c6865e

Browse files
Updated the docs
1 parent aeed58f commit 8c6865e

File tree

15 files changed

+445
-10
lines changed

15 files changed

+445
-10
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
title: Assertions
3+
---
4+
5+
A common way of highlighting unexpected behaviors in Swift is by using [assertions](https://developer.apple.com/documentation/swift/1541112-assert).
6+
7+
Inside the Stream SDKs, we use wrappers around it (`log.assert`/`log.assertionFailure`). This is because we want to allow the integrators to silence those if they want to.
8+
9+
You can change that behavior by changing the value for `assertionsEnabled` as follows:
10+
11+
```
12+
StreamRuntimeCheck.assertionsEnabled = true
13+
```
14+
15+
The default value for this property is `false`
16+
17+
Independently of the value of this flag, a message will always be printed in the console.
18+
19+
:::note
20+
When enabling Stream assertions, the default behavior of assertions still apply:
21+
- In playgrounds and -Onone builds (the default for Xcode’s Debug configuration): If the condition evaluates to false, stop program execution in a debuggable state after printing the message.
22+
- In -O builds (the default for Xcode’s Release configuration), the condition is not evaluated, and there are no effects.
23+
- In -Ounchecked builds, the condition is not evaluated, but the optimizer may assume that it always evaluates to true. Failure to satisfy that assumption is a serious programming error.
24+
25+
Read more [here](https://developer.apple.com/documentation/swift/1541112-assert).
26+
:::
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
:::note
2-
You can find more information on how the components configuration works [here](../uikit/components/custom-components.md).
2+
You can find more information on how the components configuration works [here](../uikit/custom-components.md).
33
:::

docusaurus/docs/iOS/common-content/reference-docs/stream-chat/api-client/endpoints/payloads/channel-config-properties.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ Enables message thread replies. Enabled by default.
4747
public let repliesEnabled: Bool
4848
```
4949

50+
### `quotesEnabled`
51+
52+
Enables quoting of messages. Enabled by default.
53+
54+
``` swift
55+
public let quotesEnabled: Bool
56+
```
57+
5058
### `searchEnabled`
5159

5260
Controls if messages should be searchable (this is a premium feature). Disabled by default.

docusaurus/docs/iOS/common-content/reference-docs/stream-chat/controllers/channel-controller/chat-channel-controller-properties.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ var areReactionsEnabled: Bool
135135
var areRepliesEnabled: Bool
136136
```
137137

138+
### `areQuotesEnabled`
139+
140+
`true` if the channel has quotes enabled. Defaults to `false` if the channel doesn't exist yet.
141+
142+
``` swift
143+
var areQuotesEnabled: Bool
144+
```
145+
138146
### `areReadEventsEnabled`
139147

140148
`true` if the channel has read events enabled. Defaults to `false` if the channel doesn't exist yet.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
title: Offline Support
3+
---
4+
5+
Offline support comes in 4 different aspects:
6+
7+
- Connection Recovery
8+
- Events Recovery
9+
- Queue Offline Actions (optional, enabled by default)
10+
- Keeping the DB on disk (optional, enabled by default)
11+
12+
### Connection Recovery:
13+
14+
It is really important to make sure that the app properly reconnects after a downtime, independently of what was the cause of it. It can happen that you backgrounded the app, you lost connection or maybe it was killed by yourself or the system.
15+
16+
We are listening to the app's lifecycle to make sure we perform the right set of actions to bring you up online as soon as possible
17+
18+
19+
### Events Recovery:
20+
21+
Whenever the app is not foregrounded and connected to the internet, there are likely other actions performed by other users. Especially in a Chat app, there are tons of events that can happen while you were offline.
22+
23+
To overcome this situation, we are fetching all the events that happened since the end of your last online session up until the moment you foreground the app, we are processing them and making sure the app accordingly reflects those.
24+
25+
This happens without you needing to do anything.
26+
27+
28+
### Queued Offline Actions:
29+
30+
You may be in the subway, and you are trying to send a message, but suddenly your connection drops. We make sure that this action is queued, and sent whenever you come back offline.
31+
Even if you/the system kills the app, we make sure the request is sent in your next session.
32+
33+
These are the actions that support offline queuing:
34+
- Send message
35+
- Edit message
36+
- Delete message
37+
- Add reaction
38+
- Delete reaction
39+
40+
### Keeping the DB on disk
41+
42+
By making sure that the DB stays on disk, we can guarantee that the data stays across sessions. This helps when it comes to perception. Having fewer loading states or blank pages is more engaging to the users.
43+
44+
45+
## Opting out
46+
47+
As mentioned above, you can opt-out for:
48+
- Queue Offline Actions
49+
- Keeping the DB on disk
50+
51+
To do that, you can just modify your configuration as follows:
52+
53+
```swift
54+
var config = ChatClientConfig(apiKey: .init("<# Your API Key Here #>"))
55+
config.isLocalStorageEnabled = false
56+
```

docusaurus/docs/iOS/guides/push-notifications.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ title: Push Notifications
55
Push notifications can be configured to receive updates when the application is closed or on the background. Stream Chat sends push notification to channel members that are not online and have at least one registered device. Stream supports both **Certificate-based provider connection trust (.p12 certificate)** and **Token-based provider connection trust (JWT)**. Token-based authentication is the preferred way to configure push notifications.
66

77
:::note
8-
You can find more on setting up push [here](https://getstream.io/chat/docs/php/push_ios/?language=swift). Make sure you've taken care of authentication before proceeding to the next steps.
8+
You can find more on setting up push [here](https://getstream.io/chat/docs/ios-swift/push_introduction/?language=swift). Make sure you've taken care of authentication before proceeding to the next steps.
99
:::
1010

1111
### Setup

docusaurus/docs/iOS/guides/working-with-attachments.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,12 @@ Components.default.filesAttachmentInjector = MyCustomAttachmentViewInjector.self
9393
Stream chat allows you to create your own types of attachments as well. The steps to follow to add support for a custom attachment type are the following:
9494

9595
1. Extend `AttachmentType` to include the custom type
96-
1. Create a new AttachmentPayload struct to handle your custom attachment data
97-
1. Create a new AttachmentViewInjector
96+
1. Create a new `AttachmentPayload` struct to handle your custom attachment data
97+
1. Create a typealias for `ChatMessageAttachment<AttachmentPayload>` which will be used for the content of the view
98+
1. Create a new `AttachmentViewInjector`
9899
1. Configure the SDK to use your view injector class to render custom attachments
99100

100-
Let's assume we want to attach a workout session to a message, the payload of the attachment will looks like this:
101+
Let's assume we want to attach a workout session to a message, the payload of the attachment will look like this:
101102

102103

103104
```json
@@ -111,13 +112,15 @@ Let's assume we want to attach a workout session to a message, the payload of th
111112
}
112113
```
113114

114-
Here's how we get around the first two steps:
115+
Here's how we get around the first three steps:
115116

116117
```swift
117118
public extension AttachmentType {
118119
static let workout = Self(rawValue: "workout")
119120
}
120121

122+
public typealias ChatMessageWorkoutAttachment = ChatMessageAttachment<WorkoutAttachmentPayload>
123+
121124
public struct WorkoutAttachmentPayload: AttachmentPayload {
122125
public static var type: AttachmentType = .workout
123126

docusaurus/docs/iOS/swiftui/components/message-list.md

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,43 @@ The message list view in the SwiftUI SDK allows several customization options. T
88

99
If you are developing an app with this use-case, you can customize the [message avatars](../custom-avatar), [reactions](../message-reactions), [theming and presentation logic](../../getting-started) and the different types of [attachments](../attachments).
1010

11+
## Directly Showing Channel View
12+
13+
In some cases, you want to show directly the channel view, without having a channel list as the previous screen. Here's an example how to show the channel view as an initial screen, with a predefined channel:
14+
15+
```swift
16+
@main
17+
struct TestStreamSDKApp: App {
18+
19+
@Injected(\.chatClient) var chatClient
20+
21+
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
22+
23+
var body: some Scene {
24+
WindowGroup {
25+
ChatChannelView(
26+
viewFactory: DefaultViewFactory.shared,
27+
channelController: controller
28+
)
29+
}
30+
31+
}
32+
33+
private var controller: ChatChannelController {
34+
let controller = chatClient.channelController(
35+
for: try! ChannelId(cid: "messaging:0D991C91-2"),
36+
messageOrdering: .topToBottom
37+
)
38+
39+
return controller
40+
}
41+
42+
}
43+
```
44+
1145
## Message List Configuration
1246

13-
Additionally, you can control the display of the helper views around the message (date indicators, avatars) and paddings, via the `MessageListConfig`'s properties `MessageDisplayOptions` and `MessagePaddings`. The `MessageListConfig` is part of the `Utils` class in `StreamChat`. Here's an example on how to hide the date indicators and avatars, while also increasing the horizontal padding.
47+
You can control the display of the helper views around the message (date indicators, avatars) and paddings, via the `MessageListConfig`'s properties `MessageDisplayOptions` and `MessagePaddings`. The `MessageListConfig` is part of the `Utils` class in `StreamChat`. Here's an example on how to hide the date indicators and avatars, while also increasing the horizontal padding.
1448

1549
```swift
1650
let messageDisplayOptions = MessageDisplayOptions(showAvatars: false, showMessageDate: false)
@@ -26,6 +60,29 @@ let utils = Utils(messageListConfig: messageListConfig)
2660
streamChat = StreamChat(chatClient: chatClient, utils: utils)
2761
```
2862

63+
Other config options you can enable or disable via the `MessageListConfig` are:
64+
- `messagePopoverEnabled` - the default value is true. If set to false, it will disable the message popover.
65+
- `doubleTapOverlayEnabled` - the default value is false. If set to true, you can show the message popover also with double tap.
66+
- `becomesFirstResponderOnOpen` - the default value is false. If set to true, the channel will open the keyboard on view appearance.
67+
68+
With the `MessageDisplayOptions`, you can also customize the transitions applied to the message views. The default message view transition in the SDK is `identity`. You can use the other default ones, such as `scale`, `opacity` and `slide`, or you can create your own custom transitions. Here's an example how to do this:
69+
70+
```swift
71+
var customTransition: AnyTransition {
72+
.scale.combined(with:
73+
AnyTransition.asymmetric(
74+
insertion: .move(edge: .trailing),
75+
removal: .move(edge: .leading)
76+
)
77+
)
78+
}
79+
80+
let messageDisplayOptions = MessageDisplayOptions(
81+
currentUserMessageTransition: customTransition,
82+
otherUserMessageTransition: customTransition
83+
)
84+
```
85+
2986
You can also modify the background of the message list to any SwiftUI `View` (`Color`, `LinearGradient`, `Image` etc.). In order to do this, you would need to implement the `makeMessageListBackground` method in the `ViewFactory`.
3087

3188
```swift

docusaurus/docs/iOS/swiftui/components/message-reactions.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ let appearance = Appearance(images: images)
2424
streamChat = StreamChat(chatClient: chatClient, appearance: appearance)
2525
```
2626

27+
You can also change the tint color of the reactions, by changing `reactionCurrentUserColor` for the current user's reactions, or `reactionOtherUserColor` for other users' reactions. Additionally, you can set a background for a selected reaction, with `selectedReactionBackgroundColor`. These colors are optional, so if you don't want to tint the reactions, but want to use the original icon color, you can just pass `nil` as a value. Here's an example how to change these values:
28+
29+
```swift
30+
var colors = ColorPalette()
31+
colors.reactionCurrentUserColor = UIColor.blue
32+
colors.reactionOtherUserColor = UIColor.red
33+
colors.selectedReactionBackgroundColor = UIColor.gray
34+
35+
let appearance = Appearance(colors: colors)
36+
37+
streamChat = StreamChat(chatClient: chatClient, appearance: appearance)
38+
```
39+
2740
## Changing the Message Reactions View
2841

2942
Alternatively, you can completely swap the `ReactionsContainer` view with your own implementation. In order to do that, you need to implement the `makeMessageReactionView` method from the `ViewFactory`, which is called with the message as a parameter.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
title: Dependency Injection
3+
---
4+
5+
For injecting dependencies in the SwiftUI SDK, we are using an approach based on [this article](https://www.avanderlee.com/swift/dependency-injection/). It works similarly to the @Environment in SwiftUI, but it also allows access to the dependencies in non-view related code.
6+
7+
When you initialize the SDK (by creating the `StreamChat` object), all the dependencies are created too, and you can use them anywhere in your code. In order to access a particular type, you need to use the `@Injected(\.keyPath)` property wrapper:
8+
9+
```swift
10+
@Injected(\.chatClient) var chatClient
11+
@Injected(\.fonts) var fonts
12+
@Injected(\.colors) var colors
13+
@Injected(\.images) var images
14+
@Injected(\.utils) var utils
15+
```
16+
17+
### Extending the DI with Custom Types
18+
19+
In some cases, you might also need to extend our DI mechanism with your own types. For example, you may want to be able to access your custom types like this:
20+
21+
```swift
22+
@Injected(\.customType) var customType
23+
```
24+
25+
In order to achieve this, you first need to define your own `InjectionKey`, and define it's currentValue, which basically creates the new instance of your type.
26+
27+
```swift
28+
class CustomType {
29+
// your custom logic here
30+
}
31+
32+
struct CustomInjectionKey: InjectionKey {
33+
static var currentValue: CustomType = CustomType()
34+
}
35+
```
36+
37+
Next, you need to extend our `InjectedValues` with your own custom type, by defining its getter and setter.
38+
39+
```swift
40+
extension InjectedValues {
41+
/// Provides access to the `CustomType` instance in the views and view models.
42+
var customType: CustomType {
43+
get {
44+
Self[CustomInjectionKey.self]
45+
}
46+
set {
47+
Self[CustomInjectionKey.self] = newValue
48+
}
49+
}
50+
}
51+
```
52+
53+
With these few simple steps, you can now access your custom functionality in both your app code and in your custom implementations of the views used throughout the SDK.

0 commit comments

Comments
 (0)