Skip to content

Commit

Permalink
fix: surfaceView can not be render properly in > 0.76.x
Browse files Browse the repository at this point in the history
  • Loading branch information
guoxianzhe committed Feb 26, 2025
1 parent 330ccc8 commit 56d95d7
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion ios/AgoraRtcSurfaceView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ @interface AgoraRtcSurfaceView () <RCTAgoraRtcSurfaceViewViewProtocol>

@implementation AgoraRtcSurfaceView {
UIView * _view;
BOOL _isInitialized;
BOOL _isDestroyed;
}

+ (ComponentDescriptorProvider)componentDescriptorProvider
Expand All @@ -32,6 +34,8 @@ - (instancetype)initWithFrame:(CGRect)frame
_props = defaultProps;

_view = [[UIView alloc] init];
_isInitialized = NO;
_isDestroyed = NO;

self.contentView = _view;
}
Expand All @@ -44,7 +48,17 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
const auto &oldViewProps = *std::static_pointer_cast<AgoraRtcSurfaceViewProps const>(_props);
const auto &newViewProps = *std::static_pointer_cast<AgoraRtcSurfaceViewProps const>(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;
Expand All @@ -60,11 +74,18 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
if ([[AgoraRtcNg shareInstance] irisApiEngine]) {
[[AgoraRtcNg shareInstance] irisApiEngine]->CallIrisApi(&param);
}
_isInitialized = YES;
}

[super updateProps:props oldProps:oldProps];
}

- (void)removeFromSuperview
{
[super removeFromSuperview];
_isDestroyed = YES;
}

Class<RCTComponentViewProtocol> AgoraRtcSurfaceViewCls(void)
{
return AgoraRtcSurfaceView.class;
Expand Down

0 comments on commit 56d95d7

Please sign in to comment.