Address the real lifetime issue of the SDK's Client by making Context.mediaProvider weak. (#4466)

This reverts commit 927aea4bfe.
This commit is contained in:
Doug
2025-09-05 18:18:14 +01:00
committed by GitHub
parent f30f3b1a63
commit c794144ef1
58 changed files with 380 additions and 161 deletions
@@ -65,7 +65,12 @@ class StateStoreViewModel<State: BindableState, ViewAction> {
/// An optional image loading service so that views can manage themselves
/// Intentionally non-generic so that it doesn't grow uncontrollably
let mediaProvider: MediaProviderProtocol?
///
/// We noticed that the keyboard appears to hold onto the Context of the last screen that had text input focus:
/// https://github.com/element-hq/element-x-ios/issues/4465
/// Therefore this is `weak` so that the underlying `MatrixRustSDK.Client` isn't retained when e.g. clearing
/// the cache, otherwise we have the potential for 2 `Client`s to be alive at the same time causing havoc.
private(set) weak var mediaProvider: MediaProviderProtocol?
/// Set-able/Bindable access to the bindable state.
subscript<T>(dynamicMember keyPath: WritableKeyPath<State.BindStateType, T>) -> T {