From 8f22eededd85a757c00b7dd647807e623e5f7c4d Mon Sep 17 00:00:00 2001 From: ThibaultBee <37510686+ThibaultBee@users.noreply.github.com> Date: Tue, 2 Jan 2024 12:20:55 +0100 Subject: [PATCH] feat(ios): add support for new architecture --- example/ios/_xcode.env | 11 --- ios/RNLiveStreamView.h | 20 +++++ ios/RNLiveStreamView.mm | 86 +++++++++++++++++++ ios/RNLiveStreamView.swift | 67 --------------- ios/RNLiveStreamViewImpl.swift | 1 + ...ewManager.m => RNLiveStreamViewManager.mm} | 0 ios/RNLivestream.xcodeproj/project.pbxproj | 25 +++--- react-native-livestream.podspec | 2 +- 8 files changed, 118 insertions(+), 94 deletions(-) delete mode 100644 example/ios/_xcode.env create mode 100644 ios/RNLiveStreamView.h create mode 100644 ios/RNLiveStreamView.mm delete mode 100644 ios/RNLiveStreamView.swift rename ios/{RNLiveStreamViewManager.m => RNLiveStreamViewManager.mm} (100%) diff --git a/example/ios/_xcode.env b/example/ios/_xcode.env deleted file mode 100644 index 3d5782c..0000000 --- a/example/ios/_xcode.env +++ /dev/null @@ -1,11 +0,0 @@ -# This `.xcode.env` file is versioned and is used to source the environment -# used when running script phases inside Xcode. -# To customize your local environment, you can create an `.xcode.env.local` -# file that is not versioned. - -# NODE_BINARY variable contains the PATH to the node executable. -# -# Customize the NODE_BINARY variable here. -# For example, to use nvm with brew, add the following line -# . "$(brew --prefix nvm)/nvm.sh" --no-use -export NODE_BINARY=$(command -v node) diff --git a/ios/RNLiveStreamView.h b/ios/RNLiveStreamView.h new file mode 100644 index 0000000..2136c53 --- /dev/null +++ b/ios/RNLiveStreamView.h @@ -0,0 +1,20 @@ +// This guard prevent this file to be compiled in the old architecture. +#ifdef RCT_NEW_ARCH_ENABLED +#import +#import +#import +#import +#import + +#ifndef RNLiveStreamView_h +#define RNLiveStreamView_h + +NS_ASSUME_NONNULL_BEGIN + +@interface RNLiveStreamView : RCTViewComponentView +@end + +NS_ASSUME_NONNULL_END + +#endif /* RNLiveStreamView_h */ +#endif /* RCT_NEW_ARCH_ENABLED */ diff --git a/ios/RNLiveStreamView.mm b/ios/RNLiveStreamView.mm new file mode 100644 index 0000000..2a12b72 --- /dev/null +++ b/ios/RNLiveStreamView.mm @@ -0,0 +1,86 @@ +// This guard prevent the code from being compiled in the old architecture +#ifdef RCT_NEW_ARCH_ENABLED +#import "RNLiveStreamView.h" + +#import +#import +#import +#import + +#import "RCTFabricComponentsPlugins.h" + +// MARK: Swift classes in ObjC++ +#if __has_include("react-native-livestream/react-native-livestream-Swift.h") +#import "ReactNativeAvoidSoftinput/ReactNativeAvoidSoftinput-Swift.h" +#else +#import "react-native-livestream-Swift.h" +#endif + +using namespace facebook::react; + +@class RNLiveStreamViewImpl; + +@interface RNLiveStreamView () + +@end + +// MARK: Implementation + +@implementation RNLiveStreamView { + RNLiveStreamViewImpl * _view; +} + +// MARK: Initializers +- (instancetype)initWithFrame:(CGRect)frame +{ + self = [super initWithFrame:frame]; + if (self) { + static const auto defaultProps = std::make_shared(); + _props = defaultProps; + + _view = [[RNLiveStreamViewImpl alloc] init]; + + // TODO: events + + self.contentView = _view; + } + return self; +} + +// MARK: Props +- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps +{ + const auto &oldViewProps = *std::static_pointer_cast(_props); + const auto &newViewProps = *std::static_pointer_cast(props); + + RNLiveStreamViewImpl *view = (RNLiveStreamViewImpl *)self.contentView; + + // TODO: props + + [super updateProps:props oldProps:oldProps]; +} + +// MARK: RCTComponentViewProtocol +- (void)startStreaming:(NSString *)streamKey url:(NSString *)url +{ + [_view startStreaming:streamKey url:url]; +} + +- (void)stopStreaming +{ + [_view stopStreaming]; +} + +- (void)setZoomRatioCommand:(float)zoomRatio +{ + [_view setZoomRatioCommand:zoomRatio]; +} + +@end + +Class ApiVideoLiveStreamViewCls(void) +{ + return RNLiveStreamView.class; +} + +#endif diff --git a/ios/RNLiveStreamView.swift b/ios/RNLiveStreamView.swift deleted file mode 100644 index cbc06d6..0000000 --- a/ios/RNLiveStreamView.swift +++ /dev/null @@ -1,67 +0,0 @@ -// This guard prevent the code from being compiled in the old architecture -#if RCT_NEW_ARCH_ENABLED - - import Foundation - - @objc class RNLiveStreamView: RCTViewComponentView { - init(frame: CGRect) { - super.init(frame: frame) - view = RNLiveStreamViewImpl() - } - - static func componentDescriptorProvider() -> Any! {} - - static func supplementalComponentDescriptorProviders() -> Any! {} - - func mountChildComponentView(_: UIView & RCTComponentViewProtocol, index _: Int) {} - - func unmountChildComponentView(_: UIView & RCTComponentViewProtocol, index _: Int) {} - - @objc func updateProps(_: Int32, oldProps _: Int32) {} - - func updateState(_: Int32, oldState _: Int32) {} - - func updateEventEmitter(_ eventEmitter: Int32) { - super.updateEventEmitter(eventEmitter) - } - - func updateLayoutMetrics(_: Int32, oldLayoutMetrics _: Int32) {} - - func handleCommand(_: String, args _: [Any]) {} - - func finalizeUpdates(_: Any!) {} - - func prepareForRecycle() {} - - func props() -> Any! {} - - func isJSResponder() -> Bool {} - - func setIsJSResponder(_: Bool) {} - - func setPropKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN(_: Set?) {} - - func propKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN() -> Set? {} - - @objc - func startStreaming(_ streamKey: String, url: String) { - do { - try view.startStreaming(streamKey, url: url) - } catch { - // TODO: return error - print(error) - } - } - - @objc - func stopStreaming() { - view.stopStreaming() - } - - @objc - func setZoomRatioCommand(_ zoomRatio: Float) { - view.setZoomRatio(zoomRatio: CGFloat(zoomRatio)) - } - } - -#endif diff --git a/ios/RNLiveStreamViewImpl.swift b/ios/RNLiveStreamViewImpl.swift index 5818694..58a69c1 100644 --- a/ios/RNLiveStreamViewImpl.swift +++ b/ios/RNLiveStreamViewImpl.swift @@ -51,6 +51,7 @@ extension AVCaptureDevice.Position { } } +@objc(RNLiveStreamViewImpl) class RNLiveStreamViewImpl: UIView { private var liveStream: ApiVideoLiveStream! private var isStreaming: Bool = false diff --git a/ios/RNLiveStreamViewManager.m b/ios/RNLiveStreamViewManager.mm similarity index 100% rename from ios/RNLiveStreamViewManager.m rename to ios/RNLiveStreamViewManager.mm diff --git a/ios/RNLivestream.xcodeproj/project.pbxproj b/ios/RNLivestream.xcodeproj/project.pbxproj index 98470d7..77733f0 100644 --- a/ios/RNLivestream.xcodeproj/project.pbxproj +++ b/ios/RNLivestream.xcodeproj/project.pbxproj @@ -6,12 +6,6 @@ objectVersion = 46; objects = { -/* Begin PBXBuildFile section */ - 21237D972A866EFE00A5CDCD /* RNLiveStreamViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 21237D942A866EFE00A5CDCD /* RNLiveStreamViewManager.m */; }; - 21237D982A866EFE00A5CDCD /* RNLiveStreamViewManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21237D952A866EFE00A5CDCD /* RNLiveStreamViewManager.swift */; }; - 21237D992A866EFE00A5CDCD /* RNLiveStreamView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21237D962A866EFE00A5CDCD /* RNLiveStreamView.swift */; }; -/* End PBXBuildFile section */ - /* Begin PBXCopyFilesBuildPhase section */ 58B511D91A9E6C8500147676 /* CopyFiles */ = { isa = PBXCopyFilesBuildPhase; @@ -27,9 +21,11 @@ /* Begin PBXFileReference section */ 134814201AA4EA6300B7C361 /* libRNLivestream.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNLivestream.a; sourceTree = BUILT_PRODUCTS_DIR; }; 21237D932A866EFD00A5CDCD /* RNLivestream-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RNLivestream-Bridging-Header.h"; sourceTree = ""; }; - 21237D942A866EFE00A5CDCD /* RNLiveStreamViewManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNLiveStreamViewManager.m; sourceTree = ""; }; - 21237D952A866EFE00A5CDCD /* RNLiveStreamViewManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RNLiveStreamViewManager.swift; sourceTree = ""; }; - 21237D962A866EFE00A5CDCD /* RNLiveStreamView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RNLiveStreamView.swift; sourceTree = ""; }; + 212E11F62B4468BC00FFDE96 /* RNLiveStreamViewManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RNLiveStreamViewManager.swift; sourceTree = ""; }; + 212E11F72B4468BC00FFDE96 /* RNLiveStreamViewManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNLiveStreamViewManager.m; sourceTree = ""; }; + 212E11F82B4468BD00FFDE96 /* RNLiveStreamViewImpl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RNLiveStreamViewImpl.swift; sourceTree = ""; }; + 212E11F92B4468BD00FFDE96 /* RNLiveStreamView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNLiveStreamView.m; sourceTree = ""; }; + 212E11FA2B4468BD00FFDE96 /* RNLiveStreamView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNLiveStreamView.h; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -54,9 +50,11 @@ 58B511D21A9E6C8500147676 = { isa = PBXGroup; children = ( - 21237D962A866EFE00A5CDCD /* RNLiveStreamView.swift */, - 21237D942A866EFE00A5CDCD /* RNLiveStreamViewManager.m */, - 21237D952A866EFE00A5CDCD /* RNLiveStreamViewManager.swift */, + 212E11FA2B4468BD00FFDE96 /* RNLiveStreamView.h */, + 212E11F92B4468BD00FFDE96 /* RNLiveStreamView.m */, + 212E11F82B4468BD00FFDE96 /* RNLiveStreamViewImpl.swift */, + 212E11F72B4468BC00FFDE96 /* RNLiveStreamViewManager.m */, + 212E11F62B4468BC00FFDE96 /* RNLiveStreamViewManager.swift */, 134814211AA4EA7D00B7C361 /* Products */, 21237D932A866EFD00A5CDCD /* RNLivestream-Bridging-Header.h */, ); @@ -120,9 +118,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 21237D992A866EFE00A5CDCD /* RNLiveStreamView.swift in Sources */, - 21237D982A866EFE00A5CDCD /* RNLiveStreamViewManager.swift in Sources */, - 21237D972A866EFE00A5CDCD /* RNLiveStreamViewManager.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/react-native-livestream.podspec b/react-native-livestream.podspec index a17c558..58075f1 100644 --- a/react-native-livestream.podspec +++ b/react-native-livestream.podspec @@ -31,7 +31,7 @@ Pod::Spec.new do |s| s.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"", "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1", - "CLANG_CXX_LANGUAGE_STANDARD" => "c++17" + "CLANG_CXX_LANGUAGE_STANDARD" => "c++17", } s.dependency "React-RCTFabric" s.dependency "React-Codegen"