@tenthdart/react-native-nitro-orientation-locker 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/LICENSE +21 -0
  2. package/NitroOrientationLocker.podspec +30 -0
  3. package/README.md +98 -0
  4. package/android/CMakeLists.txt +13 -0
  5. package/android/build.gradle +138 -0
  6. package/android/gradle.properties +5 -0
  7. package/android/src/main/AndroidManifest.xml +1 -0
  8. package/android/src/main/java/com/margelo/nitro/orientationlocker/HybridOrientationLocker.kt +99 -0
  9. package/ios/HybridOrientationLocker.swift +118 -0
  10. package/ios/OrientationGate.swift +22 -0
  11. package/lib/commonjs/OrientationLocker.nitro.js +6 -0
  12. package/lib/commonjs/OrientationLocker.nitro.js.map +1 -0
  13. package/lib/commonjs/OrientationLockerProvider.js +25 -0
  14. package/lib/commonjs/OrientationLockerProvider.js.map +1 -0
  15. package/lib/commonjs/index.js +33 -0
  16. package/lib/commonjs/index.js.map +1 -0
  17. package/lib/commonjs/package.json +1 -0
  18. package/lib/module/OrientationLocker.nitro.js +4 -0
  19. package/lib/module/OrientationLocker.nitro.js.map +1 -0
  20. package/lib/module/OrientationLockerProvider.js +20 -0
  21. package/lib/module/OrientationLockerProvider.js.map +1 -0
  22. package/lib/module/index.js +23 -0
  23. package/lib/module/index.js.map +1 -0
  24. package/lib/typescript/OrientationLocker.nitro.d.ts +36 -0
  25. package/lib/typescript/OrientationLocker.nitro.d.ts.map +1 -0
  26. package/lib/typescript/OrientationLockerProvider.d.ts +12 -0
  27. package/lib/typescript/OrientationLockerProvider.d.ts.map +1 -0
  28. package/lib/typescript/index.d.ts +11 -0
  29. package/lib/typescript/index.d.ts.map +1 -0
  30. package/nitro.json +24 -0
  31. package/nitrogen/generated/.gitattributes +1 -0
  32. package/nitrogen/generated/android/NitroOrientationLocker+autolinking.cmake +81 -0
  33. package/nitrogen/generated/android/NitroOrientationLocker+autolinking.gradle +27 -0
  34. package/nitrogen/generated/android/NitroOrientationLockerOnLoad.cpp +54 -0
  35. package/nitrogen/generated/android/NitroOrientationLockerOnLoad.hpp +34 -0
  36. package/nitrogen/generated/android/c++/JHybridOrientationLockerSpec.cpp +71 -0
  37. package/nitrogen/generated/android/c++/JHybridOrientationLockerSpec.hpp +66 -0
  38. package/nitrogen/generated/android/c++/JOrientation.hpp +70 -0
  39. package/nitrogen/generated/android/kotlin/com/margelo/nitro/orientationlocker/HybridOrientationLockerSpec.kt +68 -0
  40. package/nitrogen/generated/android/kotlin/com/margelo/nitro/orientationlocker/NitroOrientationLockerOnLoad.kt +35 -0
  41. package/nitrogen/generated/android/kotlin/com/margelo/nitro/orientationlocker/Orientation.kt +27 -0
  42. package/nitrogen/generated/ios/NitroOrientationLocker+autolinking.rb +62 -0
  43. package/nitrogen/generated/ios/NitroOrientationLocker-Swift-Cxx-Bridge.cpp +33 -0
  44. package/nitrogen/generated/ios/NitroOrientationLocker-Swift-Cxx-Bridge.hpp +51 -0
  45. package/nitrogen/generated/ios/NitroOrientationLocker-Swift-Cxx-Umbrella.hpp +46 -0
  46. package/nitrogen/generated/ios/NitroOrientationLockerAutolinking.mm +33 -0
  47. package/nitrogen/generated/ios/NitroOrientationLockerAutolinking.swift +26 -0
  48. package/nitrogen/generated/ios/c++/HybridOrientationLockerSpecSwift.cpp +11 -0
  49. package/nitrogen/generated/ios/c++/HybridOrientationLockerSpecSwift.hpp +99 -0
  50. package/nitrogen/generated/ios/swift/HybridOrientationLockerSpec.swift +58 -0
  51. package/nitrogen/generated/ios/swift/HybridOrientationLockerSpec_cxx.swift +171 -0
  52. package/nitrogen/generated/ios/swift/Orientation.swift +56 -0
  53. package/nitrogen/generated/shared/c++/HybridOrientationLockerSpec.cpp +25 -0
  54. package/nitrogen/generated/shared/c++/HybridOrientationLockerSpec.hpp +66 -0
  55. package/nitrogen/generated/shared/c++/Orientation.hpp +92 -0
  56. package/package.json +103 -0
  57. package/react-native.config.js +8 -0
  58. package/src/OrientationLocker.nitro.ts +45 -0
  59. package/src/OrientationLockerProvider.tsx +26 -0
  60. package/src/index.ts +30 -0
@@ -0,0 +1,27 @@
1
+ ///
2
+ /// Orientation.kt
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ package com.margelo.nitro.orientationlocker
9
+
10
+ import androidx.annotation.Keep
11
+ import com.facebook.proguard.annotations.DoNotStrip
12
+
13
+ /**
14
+ * Represents the JavaScript enum/union "Orientation".
15
+ */
16
+ @DoNotStrip
17
+ @Keep
18
+ enum class Orientation(@DoNotStrip @Keep val value: Int) {
19
+ PORTRAIT(0),
20
+ PORTRAIT_UPSIDE_DOWN(1),
21
+ LANDSCAPE_LEFT(2),
22
+ LANDSCAPE_RIGHT(3),
23
+ LANDSCAPE(4),
24
+ ALL(5);
25
+
26
+ companion object
27
+ }
@@ -0,0 +1,62 @@
1
+ #
2
+ # NitroOrientationLocker+autolinking.rb
3
+ # This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ # https://github.com/mrousavy/nitro
5
+ # Copyright © Marc Rousavy @ Margelo
6
+ #
7
+
8
+ # This is a Ruby script that adds all files generated by Nitrogen
9
+ # to the given podspec.
10
+ #
11
+ # To use it, add this to your .podspec:
12
+ # ```ruby
13
+ # Pod::Spec.new do |spec|
14
+ # # ...
15
+ #
16
+ # # Add all files generated by Nitrogen
17
+ # load 'nitrogen/generated/ios/NitroOrientationLocker+autolinking.rb'
18
+ # add_nitrogen_files(spec)
19
+ # end
20
+ # ```
21
+
22
+ def add_nitrogen_files(spec)
23
+ Pod::UI.puts "[NitroModules] 🔥 NitroOrientationLocker is boosted by nitro!"
24
+
25
+ spec.dependency "NitroModules"
26
+
27
+ current_source_files = Array(spec.attributes_hash['source_files'])
28
+ spec.source_files = current_source_files + [
29
+ # Generated cross-platform specs
30
+ "nitrogen/generated/shared/**/*.{h,hpp,c,cpp,swift}",
31
+ # Generated bridges for the cross-platform specs
32
+ "nitrogen/generated/ios/**/*.{h,hpp,c,cpp,mm,swift}",
33
+ ]
34
+
35
+ current_public_header_files = Array(spec.attributes_hash['public_header_files'])
36
+ spec.public_header_files = current_public_header_files + [
37
+ # Generated specs
38
+ "nitrogen/generated/shared/**/*.{h,hpp}",
39
+ # Swift to C++ bridging helpers
40
+ "nitrogen/generated/ios/NitroOrientationLocker-Swift-Cxx-Bridge.hpp"
41
+ ]
42
+
43
+ current_private_header_files = Array(spec.attributes_hash['private_header_files'])
44
+ spec.private_header_files = current_private_header_files + [
45
+ # iOS specific specs
46
+ "nitrogen/generated/ios/c++/**/*.{h,hpp}",
47
+ # Views are framework-specific and should be private
48
+ "nitrogen/generated/shared/**/views/**/*"
49
+ ]
50
+
51
+ current_pod_target_xcconfig = spec.attributes_hash['pod_target_xcconfig'] || {}
52
+ spec.pod_target_xcconfig = current_pod_target_xcconfig.merge({
53
+ # Use C++ 20
54
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
55
+ # Enables C++ <-> Swift interop (by default it's only ObjC)
56
+ "SWIFT_OBJC_INTEROP_MODE" => "objcxx",
57
+ # Enables stricter modular headers
58
+ "DEFINES_MODULE" => "YES",
59
+ # Disable auto-generated ObjC header for Swift (Static linkage on Xcode 26.4 breaks here)
60
+ "SWIFT_INSTALL_OBJC_HEADER" => "NO",
61
+ })
62
+ end
@@ -0,0 +1,33 @@
1
+ ///
2
+ /// NitroOrientationLocker-Swift-Cxx-Bridge.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "NitroOrientationLocker-Swift-Cxx-Bridge.hpp"
9
+
10
+ // Include C++ implementation defined types
11
+ #include "HybridOrientationLockerSpecSwift.hpp"
12
+ #include "NitroOrientationLocker-Swift-Cxx-Umbrella.hpp"
13
+ #include <NitroModules/NitroDefines.hpp>
14
+
15
+ namespace margelo::nitro::orientationlocker::bridge::swift {
16
+
17
+ // pragma MARK: std::shared_ptr<HybridOrientationLockerSpec>
18
+ std::shared_ptr<HybridOrientationLockerSpec> create_std__shared_ptr_HybridOrientationLockerSpec_(void* NON_NULL swiftUnsafePointer) noexcept {
19
+ NitroOrientationLocker::HybridOrientationLockerSpec_cxx swiftPart = NitroOrientationLocker::HybridOrientationLockerSpec_cxx::fromUnsafe(swiftUnsafePointer);
20
+ return std::make_shared<margelo::nitro::orientationlocker::HybridOrientationLockerSpecSwift>(swiftPart);
21
+ }
22
+ void* NON_NULL get_std__shared_ptr_HybridOrientationLockerSpec_(std__shared_ptr_HybridOrientationLockerSpec_ cppType) {
23
+ std::shared_ptr<margelo::nitro::orientationlocker::HybridOrientationLockerSpecSwift> swiftWrapper = std::dynamic_pointer_cast<margelo::nitro::orientationlocker::HybridOrientationLockerSpecSwift>(cppType);
24
+ #ifdef NITRO_DEBUG
25
+ if (swiftWrapper == nullptr) [[unlikely]] {
26
+ throw std::runtime_error("Class \"HybridOrientationLockerSpec\" is not implemented in Swift!");
27
+ }
28
+ #endif
29
+ NitroOrientationLocker::HybridOrientationLockerSpec_cxx& swiftPart = swiftWrapper->getSwiftPart();
30
+ return swiftPart.toUnsafe();
31
+ }
32
+
33
+ } // namespace margelo::nitro::orientationlocker::bridge::swift
@@ -0,0 +1,51 @@
1
+ ///
2
+ /// NitroOrientationLocker-Swift-Cxx-Bridge.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ // Forward declarations of C++ defined types
11
+ // Forward declaration of `HybridOrientationLockerSpec` to properly resolve imports.
12
+ namespace margelo::nitro::orientationlocker { class HybridOrientationLockerSpec; }
13
+
14
+ // Forward declarations of Swift defined types
15
+ // Forward declaration of `HybridOrientationLockerSpec_cxx` to properly resolve imports.
16
+ namespace NitroOrientationLocker { class HybridOrientationLockerSpec_cxx; }
17
+
18
+ // Include C++ defined types
19
+ #include "HybridOrientationLockerSpec.hpp"
20
+ #include <NitroModules/Result.hpp>
21
+ #include <exception>
22
+ #include <memory>
23
+
24
+ /**
25
+ * Contains specialized versions of C++ templated types so they can be accessed from Swift,
26
+ * as well as helper functions to interact with those C++ types from Swift.
27
+ */
28
+ namespace margelo::nitro::orientationlocker::bridge::swift {
29
+
30
+ // pragma MARK: std::shared_ptr<HybridOrientationLockerSpec>
31
+ /**
32
+ * Specialized version of `std::shared_ptr<HybridOrientationLockerSpec>`.
33
+ */
34
+ using std__shared_ptr_HybridOrientationLockerSpec_ = std::shared_ptr<HybridOrientationLockerSpec>;
35
+ std::shared_ptr<HybridOrientationLockerSpec> create_std__shared_ptr_HybridOrientationLockerSpec_(void* NON_NULL swiftUnsafePointer) noexcept;
36
+ void* NON_NULL get_std__shared_ptr_HybridOrientationLockerSpec_(std__shared_ptr_HybridOrientationLockerSpec_ cppType);
37
+
38
+ // pragma MARK: std::weak_ptr<HybridOrientationLockerSpec>
39
+ using std__weak_ptr_HybridOrientationLockerSpec_ = std::weak_ptr<HybridOrientationLockerSpec>;
40
+ inline std__weak_ptr_HybridOrientationLockerSpec_ weakify_std__shared_ptr_HybridOrientationLockerSpec_(const std::shared_ptr<HybridOrientationLockerSpec>& strong) noexcept { return strong; }
41
+
42
+ // pragma MARK: Result<void>
43
+ using Result_void_ = Result<void>;
44
+ inline Result_void_ create_Result_void_() noexcept {
45
+ return Result<void>::withValue();
46
+ }
47
+ inline Result_void_ create_Result_void_(const std::exception_ptr& error) noexcept {
48
+ return Result<void>::withError(error);
49
+ }
50
+
51
+ } // namespace margelo::nitro::orientationlocker::bridge::swift
@@ -0,0 +1,46 @@
1
+ ///
2
+ /// NitroOrientationLocker-Swift-Cxx-Umbrella.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ // Forward declarations of C++ defined types
11
+ // Forward declaration of `HybridOrientationLockerSpec` to properly resolve imports.
12
+ namespace margelo::nitro::orientationlocker { class HybridOrientationLockerSpec; }
13
+ // Forward declaration of `Orientation` to properly resolve imports.
14
+ namespace margelo::nitro::orientationlocker { enum class Orientation; }
15
+
16
+ // Include C++ defined types
17
+ #include "HybridOrientationLockerSpec.hpp"
18
+ #include "Orientation.hpp"
19
+ #include <NitroModules/Result.hpp>
20
+ #include <exception>
21
+ #include <memory>
22
+
23
+ // C++ helpers for Swift
24
+ #include "NitroOrientationLocker-Swift-Cxx-Bridge.hpp"
25
+
26
+ // Common C++ types used in Swift
27
+ #include <NitroModules/ArrayBufferHolder.hpp>
28
+ #include <NitroModules/AnyMapUtils.hpp>
29
+ #include <NitroModules/RuntimeError.hpp>
30
+ #include <NitroModules/DateToChronoDate.hpp>
31
+
32
+ // Forward declarations of Swift defined types
33
+ // Forward declaration of `HybridOrientationLockerSpec_cxx` to properly resolve imports.
34
+ namespace NitroOrientationLocker { class HybridOrientationLockerSpec_cxx; }
35
+
36
+ // Include Swift defined types
37
+ #if __has_include("NitroOrientationLocker-Swift.h")
38
+ // This header is generated by Xcode/Swift on every app build.
39
+ // If it cannot be found, make sure the Swift module's name (= podspec name) is actually "NitroOrientationLocker".
40
+ #include "NitroOrientationLocker-Swift.h"
41
+ // Same as above, but used when building with frameworks (`use_frameworks`)
42
+ #elif __has_include(<NitroOrientationLocker/NitroOrientationLocker-Swift.h>)
43
+ #include <NitroOrientationLocker/NitroOrientationLocker-Swift.h>
44
+ #else
45
+ #error NitroOrientationLocker's autogenerated Swift header cannot be found! Make sure the Swift module's name (= podspec name) is actually "NitroOrientationLocker", and try building the app first.
46
+ #endif
@@ -0,0 +1,33 @@
1
+ ///
2
+ /// NitroOrientationLockerAutolinking.mm
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #import <Foundation/Foundation.h>
9
+ #import <NitroModules/HybridObjectRegistry.hpp>
10
+ #import "NitroOrientationLocker-Swift-Cxx-Umbrella.hpp"
11
+ #import <type_traits>
12
+
13
+ #include "HybridOrientationLockerSpecSwift.hpp"
14
+
15
+ @interface NitroOrientationLockerAutolinking : NSObject
16
+ @end
17
+
18
+ @implementation NitroOrientationLockerAutolinking
19
+
20
+ + (void) load {
21
+ using namespace margelo::nitro;
22
+ using namespace margelo::nitro::orientationlocker;
23
+
24
+ HybridObjectRegistry::registerHybridObjectConstructor(
25
+ "OrientationLocker",
26
+ []() -> std::shared_ptr<HybridObject> {
27
+ std::shared_ptr<HybridOrientationLockerSpec> hybridObject = NitroOrientationLocker::NitroOrientationLockerAutolinking::createOrientationLocker();
28
+ return hybridObject;
29
+ }
30
+ );
31
+ }
32
+
33
+ @end
@@ -0,0 +1,26 @@
1
+ ///
2
+ /// NitroOrientationLockerAutolinking.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import NitroModules
9
+
10
+ // TODO: Use empty enums once Swift supports exporting them as namespaces
11
+ // See: https://github.com/swiftlang/swift/pull/83616
12
+ public final class NitroOrientationLockerAutolinking {
13
+ public typealias bridge = margelo.nitro.orientationlocker.bridge.swift
14
+
15
+ public static func createOrientationLocker() -> bridge.std__shared_ptr_HybridOrientationLockerSpec_ {
16
+ let hybridObject = HybridOrientationLocker()
17
+ return { () -> bridge.std__shared_ptr_HybridOrientationLockerSpec_ in
18
+ let __cxxWrapped = hybridObject.getCxxWrapper()
19
+ return __cxxWrapped.getCxxPart()
20
+ }()
21
+ }
22
+
23
+ public static func isOrientationLockerRecyclable() -> Bool {
24
+ return HybridOrientationLocker.self is any RecyclableView.Type
25
+ }
26
+ }
@@ -0,0 +1,11 @@
1
+ ///
2
+ /// HybridOrientationLockerSpecSwift.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "HybridOrientationLockerSpecSwift.hpp"
9
+
10
+ namespace margelo::nitro::orientationlocker {
11
+ } // namespace margelo::nitro::orientationlocker
@@ -0,0 +1,99 @@
1
+ ///
2
+ /// HybridOrientationLockerSpecSwift.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include "HybridOrientationLockerSpec.hpp"
11
+
12
+ // Forward declaration of `HybridOrientationLockerSpec_cxx` to properly resolve imports.
13
+ namespace NitroOrientationLocker { class HybridOrientationLockerSpec_cxx; }
14
+
15
+ // Forward declaration of `Orientation` to properly resolve imports.
16
+ namespace margelo::nitro::orientationlocker { enum class Orientation; }
17
+
18
+ #include "Orientation.hpp"
19
+
20
+ #include "NitroOrientationLocker-Swift-Cxx-Umbrella.hpp"
21
+
22
+ namespace margelo::nitro::orientationlocker {
23
+
24
+ /**
25
+ * The C++ part of HybridOrientationLockerSpec_cxx.swift.
26
+ *
27
+ * HybridOrientationLockerSpecSwift (C++) accesses HybridOrientationLockerSpec_cxx (Swift), and might
28
+ * contain some additional bridging code for C++ <> Swift interop.
29
+ *
30
+ * Since this obviously introduces an overhead, I hope at some point in
31
+ * the future, HybridOrientationLockerSpec_cxx can directly inherit from the C++ class HybridOrientationLockerSpec
32
+ * to simplify the whole structure and memory management.
33
+ */
34
+ class HybridOrientationLockerSpecSwift: public virtual HybridOrientationLockerSpec {
35
+ public:
36
+ // Constructor from a Swift instance
37
+ explicit HybridOrientationLockerSpecSwift(const NitroOrientationLocker::HybridOrientationLockerSpec_cxx& swiftPart):
38
+ HybridObject(HybridOrientationLockerSpec::TAG),
39
+ _swiftPart(swiftPart) { }
40
+
41
+ public:
42
+ // Get the Swift part
43
+ inline NitroOrientationLocker::HybridOrientationLockerSpec_cxx& getSwiftPart() noexcept {
44
+ return _swiftPart;
45
+ }
46
+
47
+ public:
48
+ inline size_t getExternalMemorySize() noexcept override {
49
+ return _swiftPart.getMemorySize();
50
+ }
51
+ bool equals(const std::shared_ptr<HybridObject>& other) override {
52
+ if (auto otherCast = std::dynamic_pointer_cast<HybridOrientationLockerSpecSwift>(other)) {
53
+ return _swiftPart.equals(otherCast->_swiftPart);
54
+ }
55
+ return false;
56
+ }
57
+ void dispose() noexcept override {
58
+ _swiftPart.dispose();
59
+ }
60
+ std::string toString() override {
61
+ return _swiftPart.toString();
62
+ }
63
+
64
+ public:
65
+ // Properties
66
+ inline bool getIsTablet() noexcept override {
67
+ return _swiftPart.isTablet();
68
+ }
69
+ inline Orientation getCurrentOrientation() noexcept override {
70
+ auto __result = _swiftPart.getCurrentOrientation();
71
+ return static_cast<Orientation>(__result);
72
+ }
73
+
74
+ public:
75
+ // Methods
76
+ inline void acquireLock(Orientation orientation) override {
77
+ auto __result = _swiftPart.acquireLock(static_cast<int>(orientation));
78
+ if (__result.hasError()) [[unlikely]] {
79
+ std::rethrow_exception(__result.error());
80
+ }
81
+ }
82
+ inline void releaseLock() override {
83
+ auto __result = _swiftPart.releaseLock();
84
+ if (__result.hasError()) [[unlikely]] {
85
+ std::rethrow_exception(__result.error());
86
+ }
87
+ }
88
+ inline void setLockTabletsToLandscape(bool enabled) override {
89
+ auto __result = _swiftPart.setLockTabletsToLandscape(std::forward<decltype(enabled)>(enabled));
90
+ if (__result.hasError()) [[unlikely]] {
91
+ std::rethrow_exception(__result.error());
92
+ }
93
+ }
94
+
95
+ private:
96
+ NitroOrientationLocker::HybridOrientationLockerSpec_cxx _swiftPart;
97
+ };
98
+
99
+ } // namespace margelo::nitro::orientationlocker
@@ -0,0 +1,58 @@
1
+ ///
2
+ /// HybridOrientationLockerSpec.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import NitroModules
9
+
10
+ /// See ``HybridOrientationLockerSpec``
11
+ public protocol HybridOrientationLockerSpec_protocol: HybridObject {
12
+ // Properties
13
+ var isTablet: Bool { get }
14
+ var currentOrientation: Orientation { get }
15
+
16
+ // Methods
17
+ func acquireLock(orientation: Orientation) throws -> Void
18
+ func releaseLock() throws -> Void
19
+ func setLockTabletsToLandscape(enabled: Bool) throws -> Void
20
+ }
21
+
22
+ public extension HybridOrientationLockerSpec_protocol {
23
+ /// Default implementation of ``HybridObject.toString``
24
+ func toString() -> String {
25
+ return "[HybridObject OrientationLocker]"
26
+ }
27
+ }
28
+
29
+ /// See ``HybridOrientationLockerSpec``
30
+ open class HybridOrientationLockerSpec_base {
31
+ private weak var cxxWrapper: HybridOrientationLockerSpec_cxx? = nil
32
+ public init() { }
33
+ public func getCxxWrapper() -> HybridOrientationLockerSpec_cxx {
34
+ #if DEBUG
35
+ guard self is any HybridOrientationLockerSpec else {
36
+ fatalError("`self` is not a `HybridOrientationLockerSpec`! Did you accidentally inherit from `HybridOrientationLockerSpec_base` instead of `HybridOrientationLockerSpec`?")
37
+ }
38
+ #endif
39
+ if let cxxWrapper = self.cxxWrapper {
40
+ return cxxWrapper
41
+ } else {
42
+ let cxxWrapper = HybridOrientationLockerSpec_cxx(self as! any HybridOrientationLockerSpec)
43
+ self.cxxWrapper = cxxWrapper
44
+ return cxxWrapper
45
+ }
46
+ }
47
+ }
48
+
49
+ /**
50
+ * A Swift base-protocol representing the OrientationLocker HybridObject.
51
+ * Implement this protocol to create Swift-based instances of OrientationLocker.
52
+ * ```swift
53
+ * class HybridOrientationLocker : HybridOrientationLockerSpec {
54
+ * // ...
55
+ * }
56
+ * ```
57
+ */
58
+ public typealias HybridOrientationLockerSpec = HybridOrientationLockerSpec_protocol & HybridOrientationLockerSpec_base
@@ -0,0 +1,171 @@
1
+ ///
2
+ /// HybridOrientationLockerSpec_cxx.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import NitroModules
9
+
10
+ /**
11
+ * A class implementation that bridges HybridOrientationLockerSpec over to C++.
12
+ * In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined.
13
+ *
14
+ * Also, some Swift types need to be bridged with special handling:
15
+ * - Enums need to be wrapped in Structs, otherwise they cannot be accessed bi-directionally (Swift bug: https://github.com/swiftlang/swift/issues/75330)
16
+ * - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper
17
+ * - Throwing methods need to be wrapped with a Result<T, Error> type, as exceptions cannot be propagated to C++
18
+ */
19
+ open class HybridOrientationLockerSpec_cxx {
20
+ /**
21
+ * The Swift <> C++ bridge's namespace (`margelo::nitro::orientationlocker::bridge::swift`)
22
+ * from `NitroOrientationLocker-Swift-Cxx-Bridge.hpp`.
23
+ * This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
24
+ */
25
+ public typealias bridge = margelo.nitro.orientationlocker.bridge.swift
26
+
27
+ /**
28
+ * Holds an instance of the `HybridOrientationLockerSpec` Swift protocol.
29
+ */
30
+ private var __implementation: any HybridOrientationLockerSpec
31
+
32
+ /**
33
+ * Holds a weak pointer to the C++ class that wraps the Swift class.
34
+ */
35
+ private var __cxxPart: bridge.std__weak_ptr_HybridOrientationLockerSpec_
36
+
37
+ /**
38
+ * Create a new `HybridOrientationLockerSpec_cxx` that wraps the given `HybridOrientationLockerSpec`.
39
+ * All properties and methods bridge to C++ types.
40
+ */
41
+ public init(_ implementation: any HybridOrientationLockerSpec) {
42
+ self.__implementation = implementation
43
+ self.__cxxPart = .init()
44
+ /* no base class */
45
+ }
46
+
47
+ /**
48
+ * Get the actual `HybridOrientationLockerSpec` instance this class wraps.
49
+ */
50
+ @inline(__always)
51
+ public func getHybridOrientationLockerSpec() -> any HybridOrientationLockerSpec {
52
+ return __implementation
53
+ }
54
+
55
+ /**
56
+ * Casts this instance to a retained unsafe raw pointer.
57
+ * This acquires one additional strong reference on the object!
58
+ */
59
+ public func toUnsafe() -> UnsafeMutableRawPointer {
60
+ return Unmanaged.passRetained(self).toOpaque()
61
+ }
62
+
63
+ /**
64
+ * Casts an unsafe pointer to a `HybridOrientationLockerSpec_cxx`.
65
+ * The pointer has to be a retained opaque `Unmanaged<HybridOrientationLockerSpec_cxx>`.
66
+ * This removes one strong reference from the object!
67
+ */
68
+ public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridOrientationLockerSpec_cxx {
69
+ return Unmanaged<HybridOrientationLockerSpec_cxx>.fromOpaque(pointer).takeRetainedValue()
70
+ }
71
+
72
+ /**
73
+ * Gets (or creates) the C++ part of this Hybrid Object.
74
+ * The C++ part is a `std::shared_ptr<HybridOrientationLockerSpec>`.
75
+ */
76
+ public func getCxxPart() -> bridge.std__shared_ptr_HybridOrientationLockerSpec_ {
77
+ let cachedCxxPart = self.__cxxPart.lock()
78
+ if Bool(fromCxx: cachedCxxPart) {
79
+ return cachedCxxPart
80
+ } else {
81
+ let newCxxPart = bridge.create_std__shared_ptr_HybridOrientationLockerSpec_(self.toUnsafe())
82
+ __cxxPart = bridge.weakify_std__shared_ptr_HybridOrientationLockerSpec_(newCxxPart)
83
+ return newCxxPart
84
+ }
85
+ }
86
+
87
+
88
+
89
+ /**
90
+ * Get the memory size of the Swift class (plus size of any other allocations)
91
+ * so the JS VM can properly track it and garbage-collect the JS object if needed.
92
+ */
93
+ @inline(__always)
94
+ public var memorySize: Int {
95
+ return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
96
+ }
97
+
98
+ /**
99
+ * Compares this object with the given [other] object for reference equality.
100
+ */
101
+ @inline(__always)
102
+ public func equals(other: HybridOrientationLockerSpec_cxx) -> Bool {
103
+ return self.__implementation === other.__implementation
104
+ }
105
+
106
+ /**
107
+ * Call dispose() on the Swift class.
108
+ * This _may_ be called manually from JS.
109
+ */
110
+ @inline(__always)
111
+ public func dispose() {
112
+ self.__implementation.dispose()
113
+ }
114
+
115
+ /**
116
+ * Call toString() on the Swift class.
117
+ */
118
+ @inline(__always)
119
+ public func toString() -> String {
120
+ return self.__implementation.toString()
121
+ }
122
+
123
+ // Properties
124
+ public final var isTablet: Bool {
125
+ @inline(__always)
126
+ get {
127
+ return self.__implementation.isTablet
128
+ }
129
+ }
130
+
131
+ public final var currentOrientation: Int32 {
132
+ @inline(__always)
133
+ get {
134
+ return self.__implementation.currentOrientation.rawValue
135
+ }
136
+ }
137
+
138
+ // Methods
139
+ @inline(__always)
140
+ public final func acquireLock(orientation: Int32) -> bridge.Result_void_ {
141
+ do {
142
+ try self.__implementation.acquireLock(orientation: margelo.nitro.orientationlocker.Orientation(rawValue: orientation)!)
143
+ return bridge.create_Result_void_()
144
+ } catch (let __error) {
145
+ let __exceptionPtr = __error.toCpp()
146
+ return bridge.create_Result_void_(__exceptionPtr)
147
+ }
148
+ }
149
+
150
+ @inline(__always)
151
+ public final func releaseLock() -> bridge.Result_void_ {
152
+ do {
153
+ try self.__implementation.releaseLock()
154
+ return bridge.create_Result_void_()
155
+ } catch (let __error) {
156
+ let __exceptionPtr = __error.toCpp()
157
+ return bridge.create_Result_void_(__exceptionPtr)
158
+ }
159
+ }
160
+
161
+ @inline(__always)
162
+ public final func setLockTabletsToLandscape(enabled: Bool) -> bridge.Result_void_ {
163
+ do {
164
+ try self.__implementation.setLockTabletsToLandscape(enabled: enabled)
165
+ return bridge.create_Result_void_()
166
+ } catch (let __error) {
167
+ let __exceptionPtr = __error.toCpp()
168
+ return bridge.create_Result_void_(__exceptionPtr)
169
+ }
170
+ }
171
+ }
@@ -0,0 +1,56 @@
1
+ ///
2
+ /// Orientation.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ /**
9
+ * Represents the JS union `Orientation`, backed by a C++ enum.
10
+ */
11
+ public typealias Orientation = margelo.nitro.orientationlocker.Orientation
12
+
13
+ public extension Orientation {
14
+ /**
15
+ * Get a Orientation for the given String value, or
16
+ * return `nil` if the given value was invalid/unknown.
17
+ */
18
+ init?(fromString string: String) {
19
+ switch string {
20
+ case "portrait":
21
+ self = .portrait
22
+ case "portrait-upside-down":
23
+ self = .portraitUpsideDown
24
+ case "landscape-left":
25
+ self = .landscapeLeft
26
+ case "landscape-right":
27
+ self = .landscapeRight
28
+ case "landscape":
29
+ self = .landscape
30
+ case "all":
31
+ self = .all
32
+ default:
33
+ return nil
34
+ }
35
+ }
36
+
37
+ /**
38
+ * Get the String value this Orientation represents.
39
+ */
40
+ var stringValue: String {
41
+ switch self {
42
+ case .portrait:
43
+ return "portrait"
44
+ case .portraitUpsideDown:
45
+ return "portrait-upside-down"
46
+ case .landscapeLeft:
47
+ return "landscape-left"
48
+ case .landscapeRight:
49
+ return "landscape-right"
50
+ case .landscape:
51
+ return "landscape"
52
+ case .all:
53
+ return "all"
54
+ }
55
+ }
56
+ }