@iternio/react-native-auto-play 0.2.0-alpha.4 → 0.2.0-alpha.7

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 (54) hide show
  1. package/README.md +1 -1
  2. package/android/src/auto/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridAndroidAutomotive.kt +25 -0
  3. package/android/src/automotive/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/AndroidTelemetryObserver.kt +2 -5
  4. package/android/src/automotive/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridAndroidAutomotive.kt +185 -0
  5. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/SignInWithGoogleActivity.kt +14 -20
  6. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/template/AutomotivePermissionRequestTemplate.kt +3 -3
  7. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/template/SignInTemplate.kt +15 -12
  8. package/android/src/main/res/drawable/google.xml +18 -0
  9. package/lib/hooks/useAndroidAutoTelemetry.d.ts +13 -4
  10. package/lib/hooks/useAndroidAutoTelemetry.js +6 -3
  11. package/lib/hooks/useIsAutoPlayFocused.d.ts +7 -0
  12. package/lib/hooks/useIsAutoPlayFocused.js +20 -0
  13. package/lib/hybrid.d.ts +2 -0
  14. package/lib/hybrid.js +2 -0
  15. package/lib/index.d.ts +4 -0
  16. package/lib/index.js +4 -0
  17. package/lib/specs/AndroidAutomotive.nitro.d.ts +33 -0
  18. package/lib/specs/AndroidAutomotive.nitro.js +13 -0
  19. package/lib/specs/AutomotivePermissionRequestTemplate.d.ts +11 -0
  20. package/lib/specs/AutomotivePermissionRequestTemplate.js +1 -0
  21. package/lib/specs/AutomotivePermissionRequestTemplate.nitro.d.ts +11 -0
  22. package/lib/specs/AutomotivePermissionRequestTemplate.nitro.js +1 -0
  23. package/lib/templates/AutomotivePermissionRequestTemplate.d.ts +23 -0
  24. package/lib/templates/AutomotivePermissionRequestTemplate.js +18 -0
  25. package/lib/types/SignInMethod.d.ts +1 -0
  26. package/nitro.json +3 -0
  27. package/nitrogen/generated/android/ReactNativeAutoPlay+autolinking.cmake +2 -0
  28. package/nitrogen/generated/android/ReactNativeAutoPlayOnLoad.cpp +16 -2
  29. package/nitrogen/generated/android/c++/JActiveCarUxRestrictions.hpp +89 -0
  30. package/nitrogen/generated/android/c++/JAppFocusState.hpp +61 -0
  31. package/nitrogen/generated/android/c++/JCarUxRestrictions.hpp +82 -0
  32. package/nitrogen/generated/android/c++/JFunc_void_ActiveCarUxRestrictions.hpp +80 -0
  33. package/nitrogen/generated/android/c++/JFunc_void_AppFocusState.hpp +78 -0
  34. package/nitrogen/generated/android/c++/JGoogleSignIn.hpp +7 -3
  35. package/nitrogen/generated/android/c++/JHybridAndroidAutomotiveSpec.cpp +120 -0
  36. package/nitrogen/generated/android/c++/JHybridAndroidAutomotiveSpec.hpp +70 -0
  37. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/ActiveCarUxRestrictions.kt +47 -0
  38. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/AppFocusState.kt +41 -0
  39. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/CarUxRestrictions.kt +31 -0
  40. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/Func_void_ActiveCarUxRestrictions.kt +80 -0
  41. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/Func_void_AppFocusState.kt +80 -0
  42. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/GoogleSignIn.kt +8 -5
  43. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridAndroidAutomotiveSpec.kt +88 -0
  44. package/nitrogen/generated/shared/c++/ActiveCarUxRestrictions.hpp +97 -0
  45. package/nitrogen/generated/shared/c++/AppFocusState.hpp +87 -0
  46. package/nitrogen/generated/shared/c++/CarUxRestrictions.hpp +81 -0
  47. package/nitrogen/generated/shared/c++/GoogleSignIn.hpp +6 -2
  48. package/nitrogen/generated/shared/c++/HybridAndroidAutomotiveSpec.cpp +25 -0
  49. package/nitrogen/generated/shared/c++/HybridAndroidAutomotiveSpec.hpp +71 -0
  50. package/package.json +1 -1
  51. package/src/hooks/useAndroidAutoTelemetry.ts +48 -32
  52. package/src/index.ts +11 -0
  53. package/src/specs/AndroidAutomotive.nitro.ts +37 -0
  54. package/src/types/SignInMethod.ts +1 -0
@@ -0,0 +1,97 @@
1
+ ///
2
+ /// ActiveCarUxRestrictions.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
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+ #if __has_include(<NitroModules/PropNameIDCache.hpp>)
26
+ #include <NitroModules/PropNameIDCache.hpp>
27
+ #else
28
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
29
+ #endif
30
+
31
+ // Forward declaration of `CarUxRestrictions` to properly resolve imports.
32
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay { enum class CarUxRestrictions; }
33
+
34
+ #include "CarUxRestrictions.hpp"
35
+ #include <vector>
36
+
37
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
38
+
39
+ /**
40
+ * A struct which can be represented as a JavaScript object (ActiveCarUxRestrictions).
41
+ */
42
+ struct ActiveCarUxRestrictions final {
43
+ public:
44
+ double maxContentDepth SWIFT_PRIVATE;
45
+ double maxCumulativeContentItems SWIFT_PRIVATE;
46
+ double maxRestrictedStringLength SWIFT_PRIVATE;
47
+ std::vector<CarUxRestrictions> activeRestrictions SWIFT_PRIVATE;
48
+
49
+ public:
50
+ ActiveCarUxRestrictions() = default;
51
+ explicit ActiveCarUxRestrictions(double maxContentDepth, double maxCumulativeContentItems, double maxRestrictedStringLength, std::vector<CarUxRestrictions> activeRestrictions): maxContentDepth(maxContentDepth), maxCumulativeContentItems(maxCumulativeContentItems), maxRestrictedStringLength(maxRestrictedStringLength), activeRestrictions(activeRestrictions) {}
52
+
53
+ public:
54
+ friend bool operator==(const ActiveCarUxRestrictions& lhs, const ActiveCarUxRestrictions& rhs) = default;
55
+ };
56
+
57
+ } // namespace margelo::nitro::swe::iternio::reactnativeautoplay
58
+
59
+ namespace margelo::nitro {
60
+
61
+ // C++ ActiveCarUxRestrictions <> JS ActiveCarUxRestrictions (object)
62
+ template <>
63
+ struct JSIConverter<margelo::nitro::swe::iternio::reactnativeautoplay::ActiveCarUxRestrictions> final {
64
+ static inline margelo::nitro::swe::iternio::reactnativeautoplay::ActiveCarUxRestrictions fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
65
+ jsi::Object obj = arg.asObject(runtime);
66
+ return margelo::nitro::swe::iternio::reactnativeautoplay::ActiveCarUxRestrictions(
67
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxContentDepth"))),
68
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxCumulativeContentItems"))),
69
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxRestrictedStringLength"))),
70
+ JSIConverter<std::vector<margelo::nitro::swe::iternio::reactnativeautoplay::CarUxRestrictions>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "activeRestrictions")))
71
+ );
72
+ }
73
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::swe::iternio::reactnativeautoplay::ActiveCarUxRestrictions& arg) {
74
+ jsi::Object obj(runtime);
75
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "maxContentDepth"), JSIConverter<double>::toJSI(runtime, arg.maxContentDepth));
76
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "maxCumulativeContentItems"), JSIConverter<double>::toJSI(runtime, arg.maxCumulativeContentItems));
77
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "maxRestrictedStringLength"), JSIConverter<double>::toJSI(runtime, arg.maxRestrictedStringLength));
78
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "activeRestrictions"), JSIConverter<std::vector<margelo::nitro::swe::iternio::reactnativeautoplay::CarUxRestrictions>>::toJSI(runtime, arg.activeRestrictions));
79
+ return obj;
80
+ }
81
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
82
+ if (!value.isObject()) {
83
+ return false;
84
+ }
85
+ jsi::Object obj = value.getObject(runtime);
86
+ if (!nitro::isPlainObject(runtime, obj)) {
87
+ return false;
88
+ }
89
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxContentDepth")))) return false;
90
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxCumulativeContentItems")))) return false;
91
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxRestrictedStringLength")))) return false;
92
+ if (!JSIConverter<std::vector<margelo::nitro::swe::iternio::reactnativeautoplay::CarUxRestrictions>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "activeRestrictions")))) return false;
93
+ return true;
94
+ }
95
+ };
96
+
97
+ } // namespace margelo::nitro
@@ -0,0 +1,87 @@
1
+ ///
2
+ /// AppFocusState.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
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+ #if __has_include(<NitroModules/PropNameIDCache.hpp>)
26
+ #include <NitroModules/PropNameIDCache.hpp>
27
+ #else
28
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
29
+ #endif
30
+
31
+
32
+
33
+ #include <optional>
34
+
35
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
36
+
37
+ /**
38
+ * A struct which can be represented as a JavaScript object (AppFocusState).
39
+ */
40
+ struct AppFocusState final {
41
+ public:
42
+ std::optional<bool> isFocusOwned SWIFT_PRIVATE;
43
+ std::optional<bool> isFocusActive SWIFT_PRIVATE;
44
+
45
+ public:
46
+ AppFocusState() = default;
47
+ explicit AppFocusState(std::optional<bool> isFocusOwned, std::optional<bool> isFocusActive): isFocusOwned(isFocusOwned), isFocusActive(isFocusActive) {}
48
+
49
+ public:
50
+ friend bool operator==(const AppFocusState& lhs, const AppFocusState& rhs) = default;
51
+ };
52
+
53
+ } // namespace margelo::nitro::swe::iternio::reactnativeautoplay
54
+
55
+ namespace margelo::nitro {
56
+
57
+ // C++ AppFocusState <> JS AppFocusState (object)
58
+ template <>
59
+ struct JSIConverter<margelo::nitro::swe::iternio::reactnativeautoplay::AppFocusState> final {
60
+ static inline margelo::nitro::swe::iternio::reactnativeautoplay::AppFocusState fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
61
+ jsi::Object obj = arg.asObject(runtime);
62
+ return margelo::nitro::swe::iternio::reactnativeautoplay::AppFocusState(
63
+ JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "isFocusOwned"))),
64
+ JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "isFocusActive")))
65
+ );
66
+ }
67
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::swe::iternio::reactnativeautoplay::AppFocusState& arg) {
68
+ jsi::Object obj(runtime);
69
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "isFocusOwned"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.isFocusOwned));
70
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "isFocusActive"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.isFocusActive));
71
+ return obj;
72
+ }
73
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
74
+ if (!value.isObject()) {
75
+ return false;
76
+ }
77
+ jsi::Object obj = value.getObject(runtime);
78
+ if (!nitro::isPlainObject(runtime, obj)) {
79
+ return false;
80
+ }
81
+ if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "isFocusOwned")))) return false;
82
+ if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "isFocusActive")))) return false;
83
+ return true;
84
+ }
85
+ };
86
+
87
+ } // namespace margelo::nitro
@@ -0,0 +1,81 @@
1
+ ///
2
+ /// CarUxRestrictions.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
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+
21
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
22
+
23
+ /**
24
+ * An enum which can be represented as a JavaScript enum (CarUxRestrictions).
25
+ */
26
+ enum class CarUxRestrictions {
27
+ UX_RESTRICTIONS_FULLY_RESTRICTED SWIFT_NAME(uxRestrictionsFullyRestricted) = 511,
28
+ UX_RESTRICTIONS_LIMIT_CONTENT SWIFT_NAME(uxRestrictionsLimitContent) = 32,
29
+ UX_RESTRICTIONS_LIMIT_STRING_LENGTH SWIFT_NAME(uxRestrictionsLimitStringLength) = 4,
30
+ UX_RESTRICTIONS_NO_DIALPAD SWIFT_NAME(uxRestrictionsNoDialpad) = 1,
31
+ UX_RESTRICTIONS_NO_FILTERING SWIFT_NAME(uxRestrictionsNoFiltering) = 2,
32
+ UX_RESTRICTIONS_NO_KEYBOARD SWIFT_NAME(uxRestrictionsNoKeyboard) = 8,
33
+ UX_RESTRICTIONS_NO_SETUP SWIFT_NAME(uxRestrictionsNoSetup) = 64,
34
+ UX_RESTRICTIONS_NO_TEXT_MESSAGE SWIFT_NAME(uxRestrictionsNoTextMessage) = 128,
35
+ UX_RESTRICTIONS_NO_VIDEO SWIFT_NAME(uxRestrictionsNoVideo) = 16,
36
+ UX_RESTRICTIONS_NO_VOICE_TRANSCRIPTION SWIFT_NAME(uxRestrictionsNoVoiceTranscription) = 256,
37
+ } CLOSED_ENUM;
38
+
39
+ } // namespace margelo::nitro::swe::iternio::reactnativeautoplay
40
+
41
+ namespace margelo::nitro {
42
+
43
+ // C++ CarUxRestrictions <> JS CarUxRestrictions (enum)
44
+ template <>
45
+ struct JSIConverter<margelo::nitro::swe::iternio::reactnativeautoplay::CarUxRestrictions> final {
46
+ static inline margelo::nitro::swe::iternio::reactnativeautoplay::CarUxRestrictions fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
47
+ int enumValue = JSIConverter<int>::fromJSI(runtime, arg);
48
+ return static_cast<margelo::nitro::swe::iternio::reactnativeautoplay::CarUxRestrictions>(enumValue);
49
+ }
50
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::swe::iternio::reactnativeautoplay::CarUxRestrictions arg) {
51
+ int enumValue = static_cast<int>(arg);
52
+ return JSIConverter<int>::toJSI(runtime, enumValue);
53
+ }
54
+ static inline bool canConvert(jsi::Runtime&, const jsi::Value& value) {
55
+ if (!value.isNumber()) {
56
+ return false;
57
+ }
58
+ double number = value.getNumber();
59
+ int integer = static_cast<int>(number);
60
+ if (number != integer) {
61
+ // The integer is not the same value as the double - we truncated floating points.
62
+ // Enums are all integers, so the input floating point number is obviously invalid.
63
+ return false;
64
+ }
65
+ switch (integer) {
66
+ case 511 /* UX_RESTRICTIONS_FULLY_RESTRICTED */: return true;
67
+ case 32 /* UX_RESTRICTIONS_LIMIT_CONTENT */: return true;
68
+ case 4 /* UX_RESTRICTIONS_LIMIT_STRING_LENGTH */: return true;
69
+ case 1 /* UX_RESTRICTIONS_NO_DIALPAD */: return true;
70
+ case 2 /* UX_RESTRICTIONS_NO_FILTERING */: return true;
71
+ case 8 /* UX_RESTRICTIONS_NO_KEYBOARD */: return true;
72
+ case 64 /* UX_RESTRICTIONS_NO_SETUP */: return true;
73
+ case 128 /* UX_RESTRICTIONS_NO_TEXT_MESSAGE */: return true;
74
+ case 16 /* UX_RESTRICTIONS_NO_VIDEO */: return true;
75
+ case 256 /* UX_RESTRICTIONS_NO_VOICE_TRANSCRIPTION */: return true;
76
+ default: return false;
77
+ }
78
+ }
79
+ };
80
+
81
+ } // namespace margelo::nitro
@@ -49,10 +49,11 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
49
49
  SignInMethods method SWIFT_PRIVATE;
50
50
  std::string serverClientId SWIFT_PRIVATE;
51
51
  std::function<void(const std::optional<std::string>& /* error */, const std::optional<GoogleSignInAccount>& /* signInAccount */)> callback SWIFT_PRIVATE;
52
+ std::string signInButtonText SWIFT_PRIVATE;
52
53
 
53
54
  public:
54
55
  GoogleSignIn() = default;
55
- explicit GoogleSignIn(SignInMethods method, std::string serverClientId, std::function<void(const std::optional<std::string>& /* error */, const std::optional<GoogleSignInAccount>& /* signInAccount */)> callback): method(method), serverClientId(serverClientId), callback(callback) {}
56
+ explicit GoogleSignIn(SignInMethods method, std::string serverClientId, std::function<void(const std::optional<std::string>& /* error */, const std::optional<GoogleSignInAccount>& /* signInAccount */)> callback, std::string signInButtonText): method(method), serverClientId(serverClientId), callback(callback), signInButtonText(signInButtonText) {}
56
57
 
57
58
  public:
58
59
  // GoogleSignIn is not equatable because these properties are not equatable: callback
@@ -70,7 +71,8 @@ namespace margelo::nitro {
70
71
  return margelo::nitro::swe::iternio::reactnativeautoplay::GoogleSignIn(
71
72
  JSIConverter<margelo::nitro::swe::iternio::reactnativeautoplay::SignInMethods>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "method"))),
72
73
  JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "serverClientId"))),
73
- JSIConverter<std::function<void(const std::optional<std::string>&, const std::optional<margelo::nitro::swe::iternio::reactnativeautoplay::GoogleSignInAccount>&)>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "callback")))
74
+ JSIConverter<std::function<void(const std::optional<std::string>&, const std::optional<margelo::nitro::swe::iternio::reactnativeautoplay::GoogleSignInAccount>&)>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "callback"))),
75
+ JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "signInButtonText")))
74
76
  );
75
77
  }
76
78
  static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::swe::iternio::reactnativeautoplay::GoogleSignIn& arg) {
@@ -78,6 +80,7 @@ namespace margelo::nitro {
78
80
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "method"), JSIConverter<margelo::nitro::swe::iternio::reactnativeautoplay::SignInMethods>::toJSI(runtime, arg.method));
79
81
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "serverClientId"), JSIConverter<std::string>::toJSI(runtime, arg.serverClientId));
80
82
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "callback"), JSIConverter<std::function<void(const std::optional<std::string>&, const std::optional<margelo::nitro::swe::iternio::reactnativeautoplay::GoogleSignInAccount>&)>>::toJSI(runtime, arg.callback));
83
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "signInButtonText"), JSIConverter<std::string>::toJSI(runtime, arg.signInButtonText));
81
84
  return obj;
82
85
  }
83
86
  static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
@@ -91,6 +94,7 @@ namespace margelo::nitro {
91
94
  if (!JSIConverter<margelo::nitro::swe::iternio::reactnativeautoplay::SignInMethods>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "method")))) return false;
92
95
  if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "serverClientId")))) return false;
93
96
  if (!JSIConverter<std::function<void(const std::optional<std::string>&, const std::optional<margelo::nitro::swe::iternio::reactnativeautoplay::GoogleSignInAccount>&)>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "callback")))) return false;
97
+ if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "signInButtonText")))) return false;
94
98
  return true;
95
99
  }
96
100
  };
@@ -0,0 +1,25 @@
1
+ ///
2
+ /// HybridAndroidAutomotiveSpec.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 "HybridAndroidAutomotiveSpec.hpp"
9
+
10
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
11
+
12
+ void HybridAndroidAutomotiveSpec::loadHybridMethods() {
13
+ // load base methods/properties
14
+ HybridObject::loadHybridMethods();
15
+ // load custom methods/properties
16
+ registerHybrids(this, [](Prototype& prototype) {
17
+ prototype.registerHybridMethod("registerCarUxRestrictionsListener", &HybridAndroidAutomotiveSpec::registerCarUxRestrictionsListener);
18
+ prototype.registerHybridMethod("getCarUxRestrictions", &HybridAndroidAutomotiveSpec::getCarUxRestrictions);
19
+ prototype.registerHybridMethod("registerAppFocusListener", &HybridAndroidAutomotiveSpec::registerAppFocusListener);
20
+ prototype.registerHybridMethod("getAppFocusState", &HybridAndroidAutomotiveSpec::getAppFocusState);
21
+ prototype.registerHybridMethod("requestAppFocus", &HybridAndroidAutomotiveSpec::requestAppFocus);
22
+ });
23
+ }
24
+
25
+ } // namespace margelo::nitro::swe::iternio::reactnativeautoplay
@@ -0,0 +1,71 @@
1
+ ///
2
+ /// HybridAndroidAutomotiveSpec.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
+ #if __has_include(<NitroModules/HybridObject.hpp>)
11
+ #include <NitroModules/HybridObject.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+
16
+ // Forward declaration of `ActiveCarUxRestrictions` to properly resolve imports.
17
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay { struct ActiveCarUxRestrictions; }
18
+ // Forward declaration of `AppFocusState` to properly resolve imports.
19
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay { struct AppFocusState; }
20
+
21
+ #include <functional>
22
+ #include "ActiveCarUxRestrictions.hpp"
23
+ #include "AppFocusState.hpp"
24
+
25
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
26
+
27
+ using namespace margelo::nitro;
28
+
29
+ /**
30
+ * An abstract base class for `AndroidAutomotive`
31
+ * Inherit this class to create instances of `HybridAndroidAutomotiveSpec` in C++.
32
+ * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
33
+ * @example
34
+ * ```cpp
35
+ * class HybridAndroidAutomotive: public HybridAndroidAutomotiveSpec {
36
+ * public:
37
+ * HybridAndroidAutomotive(...): HybridObject(TAG) { ... }
38
+ * // ...
39
+ * };
40
+ * ```
41
+ */
42
+ class HybridAndroidAutomotiveSpec: public virtual HybridObject {
43
+ public:
44
+ // Constructor
45
+ explicit HybridAndroidAutomotiveSpec(): HybridObject(TAG) { }
46
+
47
+ // Destructor
48
+ ~HybridAndroidAutomotiveSpec() override = default;
49
+
50
+ public:
51
+ // Properties
52
+
53
+
54
+ public:
55
+ // Methods
56
+ virtual std::function<void()> registerCarUxRestrictionsListener(const std::function<void(const ActiveCarUxRestrictions& /* restrictions */)>& callback) = 0;
57
+ virtual ActiveCarUxRestrictions getCarUxRestrictions() = 0;
58
+ virtual std::function<void()> registerAppFocusListener(const std::function<void(const AppFocusState& /* state */)>& callback) = 0;
59
+ virtual AppFocusState getAppFocusState() = 0;
60
+ virtual std::function<void()> requestAppFocus() = 0;
61
+
62
+ protected:
63
+ // Hybrid Setup
64
+ void loadHybridMethods() override;
65
+
66
+ protected:
67
+ // Tag for logging
68
+ static constexpr auto TAG = "AndroidAutomotive";
69
+ };
70
+
71
+ } // namespace margelo::nitro::swe::iternio::reactnativeautoplay
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iternio/react-native-auto-play",
3
- "version": "0.2.0-alpha.4",
3
+ "version": "0.2.0-alpha.7",
4
4
  "description": "Android Auto and Apple CarPlay for react-native",
5
5
  "main": "lib/index",
6
6
  "module": "lib/index",
@@ -4,35 +4,46 @@ import { HybridAndroidAutoTelemetry, HybridAutoPlay } from '..';
4
4
 
5
5
  import type { AndroidAutoPermissions, Telemetry } from '../types/Telemetry';
6
6
 
7
- interface Props {
8
- /**
9
- * Can be used to delay asking for permissions if set to false. True by default.
10
- * Can be used to request other permissions first, so the permission request dialogs do not overlap.
11
- * @default true
12
- */
13
- requestTelemetryPermissions?: boolean;
14
- /**
15
- * The permissions to check.
16
- */
17
- requiredPermissions: Array<AndroidAutoPermissions>;
18
- /**
19
- * Android Automotive specific permission request properties
20
- */
21
- automotivePermissionRequest?: {
22
- /**
23
- * message to be shown on the permission request screen
24
- */
25
- message: string;
26
- /**
27
- * primary action button text
28
- */
29
- grantButtonText: string;
30
- /**
31
- * secondary action button text, if not specified button will not be shown
32
- */
33
- cancelButtonText?: string;
34
- };
35
- }
7
+ type Props =
8
+ | {
9
+ /**
10
+ * Can be used to delay asking for permissions if set to false. True by default.
11
+ * Can be used to request other permissions first, so the permission request dialogs do not overlap.
12
+ * @default true
13
+ */
14
+ requestTelemetryPermissions: true;
15
+ /**
16
+ * The permissions to check.
17
+ */
18
+ requiredPermissions: Array<AndroidAutoPermissions>;
19
+ /**
20
+ * Android Automotive specific permission request properties
21
+ */
22
+ automotivePermissionRequest?: {
23
+ /**
24
+ * message to be shown on the permission request screen
25
+ */
26
+ message: string;
27
+ /**
28
+ * primary action button text
29
+ */
30
+ grantButtonText: string;
31
+ /**
32
+ * secondary action button text, if not specified button will not be shown
33
+ */
34
+ cancelButtonText?: string;
35
+ };
36
+ /**
37
+ * set to true in case your build variant targets Android Automotive
38
+ */
39
+ isAndroidAutomotive?: boolean;
40
+ }
41
+ | {
42
+ requestTelemetryPermissions: false | undefined;
43
+ requiredPermissions?: never;
44
+ automotivePermissionRequest?: never;
45
+ isAndroidAutomotive?: boolean;
46
+ };
36
47
 
37
48
  /**
38
49
  * Hook to check if the telemetry permissions are granted. If the permissions are not granted, it will request them from the user.
@@ -43,15 +54,20 @@ interface Props {
43
54
  */
44
55
  export const useAndroidAutoTelemetry = ({
45
56
  requestTelemetryPermissions = true,
46
- requiredPermissions,
57
+ requiredPermissions = [],
47
58
  automotivePermissionRequest,
59
+ isAndroidAutomotive = false,
48
60
  }: Props) => {
49
61
  const [permissionsGranted, setPermissionsGranted] = useState<boolean | null>(null);
50
62
  const [telemetry, setTelemetry] = useState<Telemetry | undefined>(undefined);
51
63
  const [error, setError] = useState<string | undefined>(undefined);
52
- const [isConnected, setIsConnected] = useState(false);
64
+ const [isConnected, setIsConnected] = useState(isAndroidAutomotive);
53
65
 
54
66
  useEffect(() => {
67
+ if (isAndroidAutomotive) {
68
+ return;
69
+ }
70
+
55
71
  const removeDidConnect = HybridAutoPlay.addListener('didConnect', () => setIsConnected(true));
56
72
  const removeDidDisconnect = HybridAutoPlay.addListener('didDisconnect', () =>
57
73
  setIsConnected(false)
@@ -63,7 +79,7 @@ export const useAndroidAutoTelemetry = ({
63
79
  removeDidConnect();
64
80
  removeDidDisconnect();
65
81
  };
66
- }, []);
82
+ }, [isAndroidAutomotive]);
67
83
 
68
84
  useEffect(() => {
69
85
  const checkPermissions = async () => {
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Platform } from 'react-native';
2
2
  import { NitroModules } from 'react-native-nitro-modules';
3
3
  import AutoPlayHeadlessJsTask from './AutoPlayHeadlessJsTask';
4
+ import type { AndroidAutomotive } from './specs/AndroidAutomotive.nitro';
4
5
  import type { AndroidAutoTelemetry as NitroAndroidAutoTelemetry } from './specs/AndroidAutoTelemetry.nitro';
5
6
  import type { AutoPlay as NitroAutoPlay } from './specs/AutoPlay.nitro';
6
7
 
@@ -13,6 +14,11 @@ export const HybridAndroidAutoTelemetry =
13
14
  ? NitroModules.createHybridObject<NitroAndroidAutoTelemetry>('AndroidAutoTelemetry')
14
15
  : null;
15
16
 
17
+ export const HybridAndroidAutomotive =
18
+ Platform.OS === 'android'
19
+ ? NitroModules.createHybridObject<AndroidAutomotive>('AndroidAutomotive')
20
+ : null;
21
+
16
22
  /**
17
23
  * These are the static module names for the app running on the mobile device, head unit screen and the CarPlay dashboard.
18
24
  * Clusters generate uuids on native side that are passed in the RootComponentInitialProps
@@ -31,6 +37,11 @@ export * from './hooks/useSafeAreaInsets';
31
37
  export * from './hooks/useVoiceInput';
32
38
  export * from './scenes/AutoPlayCluster';
33
39
  export * from './scenes/CarPlayDashboardScene';
40
+ export type {
41
+ ActiveCarUxRestrictions,
42
+ AppFocusState,
43
+ } from './specs/AndroidAutomotive.nitro';
44
+ export { CarUxRestrictions } from './specs/AndroidAutomotive.nitro';
34
45
  export * from './templates/GridTemplate';
35
46
  export * from './templates/InformationTemplate';
36
47
  export * from './templates/ListTemplate';
@@ -0,0 +1,37 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules';
2
+ import type { CleanupCallback } from '../types/Event';
3
+
4
+ export enum CarUxRestrictions {
5
+ UX_RESTRICTIONS_FULLY_RESTRICTED = 511,
6
+ UX_RESTRICTIONS_LIMIT_CONTENT = 32,
7
+ UX_RESTRICTIONS_LIMIT_STRING_LENGTH = 4,
8
+ UX_RESTRICTIONS_NO_DIALPAD = 1,
9
+ UX_RESTRICTIONS_NO_FILTERING = 2,
10
+ UX_RESTRICTIONS_NO_KEYBOARD = 8,
11
+ UX_RESTRICTIONS_NO_SETUP = 64,
12
+ UX_RESTRICTIONS_NO_TEXT_MESSAGE = 128,
13
+ UX_RESTRICTIONS_NO_VIDEO = 16,
14
+ UX_RESTRICTIONS_NO_VOICE_TRANSCRIPTION = 256,
15
+ }
16
+
17
+ export interface ActiveCarUxRestrictions {
18
+ maxContentDepth: number;
19
+ maxCumulativeContentItems: number;
20
+ maxRestrictedStringLength: number;
21
+ activeRestrictions: Array<CarUxRestrictions>;
22
+ }
23
+
24
+ export interface AppFocusState {
25
+ isFocusOwned?: boolean;
26
+ isFocusActive?: boolean;
27
+ }
28
+
29
+ export interface AndroidAutomotive extends HybridObject<{ android: 'kotlin' }> {
30
+ registerCarUxRestrictionsListener(
31
+ callback: (restrictions: ActiveCarUxRestrictions) => void
32
+ ): CleanupCallback;
33
+ getCarUxRestrictions(): ActiveCarUxRestrictions;
34
+ registerAppFocusListener(callback: (state: AppFocusState) => void): CleanupCallback;
35
+ getAppFocusState(): AppFocusState;
36
+ requestAppFocus(): CleanupCallback;
37
+ }
@@ -20,6 +20,7 @@ export type GoogleSignIn = {
20
20
  method: SignInMethods.GOOGLE;
21
21
  serverClientId: string;
22
22
  callback: (error?: string, signInAccount?: GoogleSignInAccount) => void;
23
+ signInButtonText: string;
23
24
  };
24
25
 
25
26
  export type PinSignIn = {