Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ipavlidakis committed May 10, 2024
1 parent b4c6693 commit bc05fa8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ fileprivate func content() {
var body: some View {
YourRootView()
.modifier(CallModifier(viewModel: viewModel))
.onCallEnded(additionalPresentationValidator: { $0?.state.createdBy?.id == streamVideo.user.id }) { call, dismiss in
.onCallEnded(presentationValidator: { $0?.state.createdBy?.id == streamVideo.user.id }) { call, dismiss in
if let call {
DemoFeedbackView(call, dismiss: dismiss)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ private final class CallEndedViewModifierViewModel: ObservableObject {
@available(iOS 14.0, *)
private struct CallEndedViewModifier<Subview: View>: ViewModifier {

private var additionalPresentationValidator: (Call?) -> Bool
private var presentationValidator: (Call?) -> Bool
private var subviewProvider: (Call?, @escaping () -> Void) -> Subview

@StateObject private var viewModel: CallEndedViewModifierViewModel

init(
additionalPresentationValidator: @escaping (Call?) -> Bool,
presentationValidator: @escaping (Call?) -> Bool,
@ViewBuilder subviewProvider: @escaping (Call?, @escaping () -> Void) -> Subview
) {
self.additionalPresentationValidator = additionalPresentationValidator
self.presentationValidator = presentationValidator
self.subviewProvider = subviewProvider
_viewModel = .init(wrappedValue: .init())
}
Expand All @@ -62,7 +62,7 @@ private struct CallEndedViewModifier<Subview: View>: ViewModifier {
switch (call, viewModel.lastCall, viewModel.isPresentingSubview) {
case (nil, let activeCall, false)
where activeCall != nil && viewModel
.maxParticipantsCount > 1 && additionalPresentationValidator(viewModel.lastCall):
.maxParticipantsCount > 1 && presentationValidator(viewModel.lastCall):
/// The following presentation criteria are required:
/// - The activeCall was ended.
/// - Participants, during call's duration, grew to more than one.
Expand Down Expand Up @@ -105,16 +105,16 @@ private struct CallEndedViewModifier<Subview: View>: ViewModifier {
@available(iOS, introduced: 13, obsoleted: 14)
private struct CallEndedViewModifier_iOS13<Subview: View>: ViewModifier {

private var additionalPresentationValidator: (Call?) -> Bool
private var presentationValidator: (Call?) -> Bool
private var subviewProvider: (Call?, @escaping () -> Void) -> Subview

@BackportStateObject private var viewModel: CallEndedViewModifierViewModel

init(
additionalPresentationValidator: @escaping (Call?) -> Bool,
presentationValidator: @escaping (Call?) -> Bool,
@ViewBuilder subviewProvider: @escaping (Call?, @escaping () -> Void) -> Subview
) {
self.additionalPresentationValidator = additionalPresentationValidator
self.presentationValidator = presentationValidator
self.subviewProvider = subviewProvider
_viewModel = .init(wrappedValue: .init())
}
Expand All @@ -136,7 +136,7 @@ private struct CallEndedViewModifier_iOS13<Subview: View>: ViewModifier {
switch (call, viewModel.lastCall, viewModel.isPresentingSubview) {
case (nil, let activeCall, false)
where activeCall != nil && viewModel
.maxParticipantsCount > 1 && additionalPresentationValidator(viewModel.lastCall):
.maxParticipantsCount > 1 && presentationValidator(viewModel.lastCall):
/// The following presentation criteria are required:
/// - The activeCall was ended.
/// - Participants, during call's duration, grew to more than one.
Expand Down Expand Up @@ -185,26 +185,26 @@ extension View {
/// - Participants, during call's duration, grew to more than one.
///
/// - Parameters:
/// - additionalPresentationValidator: A closure that can be used to provide additional
/// - presentationValidator: A closure that can be used to provide additional
/// validation rules for presentation. The modifier will inject the last available call when calling.
/// - content: A viewBuilder that returns the modal's content. The viewModifier
/// will provide a dismiss closure that can be called from the content to close the modal.
@ViewBuilder
public func onCallEnded(
additionalPresentationValidator: @escaping (Call?) -> Bool = { _ in true },
presentationValidator: @escaping (Call?) -> Bool = { _ in true },
@ViewBuilder _ content: @escaping (Call?, @escaping () -> Void) -> some View
) -> some View {
if #available(iOS 14.0, *) {
modifier(
CallEndedViewModifier(
additionalPresentationValidator: additionalPresentationValidator,
presentationValidator: presentationValidator,
subviewProvider: content
)
)
} else {
modifier(
CallEndedViewModifier_iOS13(
additionalPresentationValidator: additionalPresentationValidator,
presentationValidator: presentationValidator,
subviewProvider: content
)
)
Expand Down
8 changes: 4 additions & 4 deletions docusaurus/docs/iOS/05-ui-cookbook/18-call-quality-rating.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ struct DemoStarRatingView: View {
}
```

With the FeedbackView declared, the next step is to find a way to inject the View in the call's lifecycle in order to be presented to the user at the right time. To simplify this step, the Swift Video SDK provides the `onCallEnded` ViewModifier . The modifier accepts two closures with inputs an optional `Call` object while onlye the second one also receives a dismiss closure.
With the FeedbackView declared, the next step is to find a way to inject the View in the call's lifecycle in order to be presented to the user at the right time. To simplify this step, the Swift Video SDK provides the `onCallEnded` ViewModifier . The modifier accepts two closures with inputs an optional `Call` object while only the second one also receives a dismiss closure.

The first closure can be used to provide additional logic when calculating the decision to present or not the modal. The second closure is a `ViewBuilder` that will be called to provide the modal's content.

Expand All @@ -197,7 +197,7 @@ struct CallContainer: View {
var body: some View {
YourRootView()
.modifier(CallModifier(viewModel: viewModel))
.onCallEnded(additionalPresentationValidator: { call in call?.state.createdBy?.id == streamVideo.user.id }) { call, dismiss in
.onCallEnded(presentationValidator: { call in call?.state.createdBy?.id == streamVideo.user.id }) { call, dismiss in
if let call {
DemoFeedbackView(call, dismiss: dismiss)
}
Expand All @@ -209,10 +209,10 @@ struct CallContainer: View {
The ViewModifier observes the Call's lifecycle and looks for the following triggering criteria:
- Once the active call has ended
- If the max number of joined participants, during call's duration, grew to more than one
- It will evaluate the `additionalPresentationValidator`
- It will evaluate the `presentationValidator`

Then the modifier will trigger the provided closure and will expect a view that will presented inside the modal.

:::note
The ViewModifier will provide you with a dismiss closure that you can use in your UI to dismiss the modal.
:::
:::

0 comments on commit bc05fa8

Please sign in to comment.