From 56d95d7b5aec9a1be6947b439a4a4ea7d8e5d1cd Mon Sep 17 00:00:00 2001 From: gxz Date: Wed, 26 Feb 2025 19:39:39 +0800 Subject: [PATCH] fix: surfaceView can not be render properly in > 0.76.x --- ios/AgoraRtcSurfaceView.mm | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/ios/AgoraRtcSurfaceView.mm b/ios/AgoraRtcSurfaceView.mm index 618e8aaab..4fde0cde1 100644 --- a/ios/AgoraRtcSurfaceView.mm +++ b/ios/AgoraRtcSurfaceView.mm @@ -18,6 +18,8 @@ @interface AgoraRtcSurfaceView () @implementation AgoraRtcSurfaceView { UIView * _view; + BOOL _isInitialized; + BOOL _isDestroyed; } + (ComponentDescriptorProvider)componentDescriptorProvider @@ -32,6 +34,8 @@ - (instancetype)initWithFrame:(CGRect)frame _props = defaultProps; _view = [[UIView alloc] init]; + _isInitialized = NO; + _isDestroyed = NO; self.contentView = _view; } @@ -44,7 +48,17 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const & const auto &oldViewProps = *std::static_pointer_cast(_props); const auto &newViewProps = *std::static_pointer_cast(props); - if (oldViewProps.callApi.funcName != newViewProps.callApi.funcName || oldViewProps.callApi.params != newViewProps.callApi.params) { + // Add NSLog to print oldViewProps and newViewProps + NSLog(@"oldViewProps: funcName = %s, params = %s", oldViewProps.callApi.funcName.c_str(), oldViewProps.callApi.params.c_str()); + NSLog(@"newViewProps: funcName = %s, params = %s", newViewProps.callApi.funcName.c_str(), newViewProps.callApi.params.c_str()); + NSLog(@"_isInitialized: _isInitialized = %d", _isInitialized); + + if (_isDestroyed) { + _isInitialized = NO; + _isDestroyed = NO; + } + + if (!_isInitialized || oldViewProps.callApi.funcName != newViewProps.callApi.funcName || oldViewProps.callApi.params != newViewProps.callApi.params) { char result[kBasicResultLength]; void *buffers[1]; buffers[0] = (__bridge void*)_view; @@ -60,11 +74,18 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const & if ([[AgoraRtcNg shareInstance] irisApiEngine]) { [[AgoraRtcNg shareInstance] irisApiEngine]->CallIrisApi(¶m); } + _isInitialized = YES; } [super updateProps:props oldProps:oldProps]; } +- (void)removeFromSuperview +{ + [super removeFromSuperview]; + _isDestroyed = YES; +} + Class AgoraRtcSurfaceViewCls(void) { return AgoraRtcSurfaceView.class;