react-native-nitro-country-picker 0.1.0
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.
- package/LICENSE +20 -0
- package/NitroCountryPicker.podspec +37 -0
- package/README.md +164 -0
- package/android/CMakeLists.txt +24 -0
- package/android/build.gradle +149 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +8 -0
- package/android/src/main/cpp/cpp-adapter.cpp +6 -0
- package/android/src/main/java/com/margelo/nitro/nitrocountrypicker/CountryPickerActivity.kt +95 -0
- package/android/src/main/java/com/margelo/nitro/nitrocountrypicker/NitroCountryPicker.kt +132 -0
- package/android/src/main/java/com/margelo/nitro/nitrocountrypicker/NitroCountryPickerPackage.kt +36 -0
- package/ios/NitroCountryPicker.swift +94 -0
- package/lib/module/NitroCountryPicker.nitro.js +4 -0
- package/lib/module/NitroCountryPicker.nitro.js.map +1 -0
- package/lib/module/index.js +11 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NitroCountryPicker.nitro.d.ts +17 -0
- package/lib/typescript/src/NitroCountryPicker.nitro.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +4 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/nitro.json +23 -0
- package/nitrogen/generated/android/c++/JHybridNitroCountryPickerSpec.cpp +83 -0
- package/nitrogen/generated/android/c++/JHybridNitroCountryPickerSpec.hpp +64 -0
- package/nitrogen/generated/android/c++/JIPickedCountry.hpp +65 -0
- package/nitrogen/generated/android/c++/JPickCountryOptions.hpp +58 -0
- package/nitrogen/generated/android/c++/JVariant_NullType_IPickedCountry.cpp +26 -0
- package/nitrogen/generated/android/c++/JVariant_NullType_IPickedCountry.hpp +72 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocountrypicker/HybridNitroCountryPickerSpec.kt +60 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocountrypicker/IPickedCountry.kt +44 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocountrypicker/PickCountryOptions.kt +38 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocountrypicker/Variant_NullType_IPickedCountry.kt +53 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocountrypicker/nitrocountrypickerOnLoad.kt +35 -0
- package/nitrogen/generated/android/nitrocountrypicker+autolinking.cmake +82 -0
- package/nitrogen/generated/android/nitrocountrypicker+autolinking.gradle +27 -0
- package/nitrogen/generated/android/nitrocountrypickerOnLoad.cpp +54 -0
- package/nitrogen/generated/android/nitrocountrypickerOnLoad.hpp +34 -0
- package/nitrogen/generated/ios/NitroCountryPicker+autolinking.rb +60 -0
- package/nitrogen/generated/ios/NitroCountryPicker-Swift-Cxx-Bridge.cpp +49 -0
- package/nitrogen/generated/ios/NitroCountryPicker-Swift-Cxx-Bridge.hpp +188 -0
- package/nitrogen/generated/ios/NitroCountryPicker-Swift-Cxx-Umbrella.hpp +54 -0
- package/nitrogen/generated/ios/NitroCountryPickerAutolinking.mm +33 -0
- package/nitrogen/generated/ios/NitroCountryPickerAutolinking.swift +26 -0
- package/nitrogen/generated/ios/c++/HybridNitroCountryPickerSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNitroCountryPickerSpecSwift.hpp +99 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__variant_nitro__NullType__IPickedCountry_.swift +58 -0
- package/nitrogen/generated/ios/swift/HybridNitroCountryPickerSpec.swift +56 -0
- package/nitrogen/generated/ios/swift/HybridNitroCountryPickerSpec_cxx.swift +171 -0
- package/nitrogen/generated/ios/swift/IPickedCountry.swift +39 -0
- package/nitrogen/generated/ios/swift/PickCountryOptions.swift +42 -0
- package/nitrogen/generated/ios/swift/Variant_NullType_IPickedCountry.swift +18 -0
- package/nitrogen/generated/shared/c++/HybridNitroCountryPickerSpec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridNitroCountryPickerSpec.hpp +71 -0
- package/nitrogen/generated/shared/c++/IPickedCountry.hpp +91 -0
- package/nitrogen/generated/shared/c++/PickCountryOptions.hpp +84 -0
- package/package.json +175 -0
- package/src/NitroCountryPicker.nitro.ts +20 -0
- package/src/index.tsx +19 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import CountryPickerAKS
|
|
2
|
+
import NitroModules
|
|
3
|
+
import React
|
|
4
|
+
import UIKit
|
|
5
|
+
|
|
6
|
+
class NitroCountryPicker: HybridNitroCountryPickerSpec {
|
|
7
|
+
private var lastPickedCountry: IPickedCountry? = nil
|
|
8
|
+
private var pendingPickPromise: Promise<Variant_NullType_IPickedCountry>? = nil
|
|
9
|
+
|
|
10
|
+
private func makeError(_ message: String) -> Error {
|
|
11
|
+
return NSError(
|
|
12
|
+
domain: "NitroCountryPicker", code: 1, userInfo: [NSLocalizedDescriptionKey: message])
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@MainActor
|
|
16
|
+
private func resolvePendingPick(country: IPickedCountry?) {
|
|
17
|
+
guard let promise = pendingPickPromise else {
|
|
18
|
+
return
|
|
19
|
+
}
|
|
20
|
+
pendingPickPromise = nil
|
|
21
|
+
|
|
22
|
+
let result: Variant_NullType_IPickedCountry = country.map { .second($0) } ?? .first(.null)
|
|
23
|
+
promise.resolve(withResult: result)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@MainActor
|
|
27
|
+
private func rejectPendingPick(error: Error) {
|
|
28
|
+
guard let promise = pendingPickPromise else {
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
pendingPickPromise = nil
|
|
32
|
+
|
|
33
|
+
promise.reject(withError: error)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@MainActor
|
|
37
|
+
private func openPicker(
|
|
38
|
+
options: PickCountryOptions?,
|
|
39
|
+
promise: Promise<Variant_NullType_IPickedCountry>
|
|
40
|
+
) {
|
|
41
|
+
if pendingPickPromise != nil {
|
|
42
|
+
promise.reject(withError: makeError("Country picker is already open."))
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
pendingPickPromise = promise
|
|
46
|
+
|
|
47
|
+
guard let presenter = RCTPresentedViewController() else {
|
|
48
|
+
rejectPendingPick(
|
|
49
|
+
error: makeError("No active UIViewController available to present country picker."))
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// CountryPickerAKS does not expose a dedicated header-title config yet.
|
|
54
|
+
_ = options?.headerTitle
|
|
55
|
+
|
|
56
|
+
CountryPicker.show(from: presenter) { [weak self] result in
|
|
57
|
+
guard let self else { return }
|
|
58
|
+
switch result {
|
|
59
|
+
case .success(let selected):
|
|
60
|
+
let picked = IPickedCountry(
|
|
61
|
+
name: selected.name,
|
|
62
|
+
dialCode: selected.dial_code,
|
|
63
|
+
code: selected.code
|
|
64
|
+
)
|
|
65
|
+
self.lastPickedCountry = picked
|
|
66
|
+
self.resolvePendingPick(country: picked)
|
|
67
|
+
case .failure(let error):
|
|
68
|
+
switch error {
|
|
69
|
+
case .NotSelected:
|
|
70
|
+
self.resolvePendingPick(country: nil)
|
|
71
|
+
default:
|
|
72
|
+
self.rejectPendingPick(error: error)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
func pickCountry(options: PickCountryOptions?) throws -> Promise<Variant_NullType_IPickedCountry>
|
|
79
|
+
{
|
|
80
|
+
let promise = Promise<Variant_NullType_IPickedCountry>()
|
|
81
|
+
Task { @MainActor [weak self] in
|
|
82
|
+
guard let self else { return }
|
|
83
|
+
self.openPicker(options: options, promise: promise)
|
|
84
|
+
}
|
|
85
|
+
return promise
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
func getLastPickedCountry() throws -> Variant_NullType_IPickedCountry {
|
|
89
|
+
if let picked = lastPickedCountry {
|
|
90
|
+
return .second(picked)
|
|
91
|
+
}
|
|
92
|
+
return .first(.null)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../src","sources":["NitroCountryPicker.nitro.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
4
|
+
const NitroCountryPickerHybridObject = NitroModules.createHybridObject('NitroCountryPicker');
|
|
5
|
+
export function pickCountry(options) {
|
|
6
|
+
return NitroCountryPickerHybridObject.pickCountry(options);
|
|
7
|
+
}
|
|
8
|
+
export function getLastPickedCountry() {
|
|
9
|
+
return NitroCountryPickerHybridObject.getLastPickedCountry();
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NitroModules","NitroCountryPickerHybridObject","createHybridObject","pickCountry","options","getLastPickedCountry"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,4BAA4B;AAOzD,MAAMC,8BAA8B,GAClCD,YAAY,CAACE,kBAAkB,CAAqB,oBAAoB,CAAC;AAE3E,OAAO,SAASC,WAAWA,CACzBC,OAA4B,EACI;EAChC,OAAOH,8BAA8B,CAACE,WAAW,CAACC,OAAO,CAAC;AAC5D;AAEA,OAAO,SAASC,oBAAoBA,CAAA,EAA0B;EAC5D,OAAOJ,8BAA8B,CAACI,oBAAoB,CAAC,CAAC;AAC9D","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
|
+
export interface IPickedCountry {
|
|
3
|
+
name: string;
|
|
4
|
+
dialCode: string;
|
|
5
|
+
code: string;
|
|
6
|
+
}
|
|
7
|
+
export interface PickCountryOptions {
|
|
8
|
+
headerTitle?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface NitroCountryPicker extends HybridObject<{
|
|
11
|
+
ios: 'swift';
|
|
12
|
+
android: 'kotlin';
|
|
13
|
+
}> {
|
|
14
|
+
pickCountry(options?: PickCountryOptions): Promise<IPickedCountry | null>;
|
|
15
|
+
getLastPickedCountry(): IPickedCountry | null;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=NitroCountryPicker.nitro.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NitroCountryPicker.nitro.d.ts","sourceRoot":"","sources":["../../../src/NitroCountryPicker.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/D,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,kBAAkB;IACjC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,kBAAmB,SAAQ,YAAY,CAAC;IACvD,GAAG,EAAE,OAAO,CAAC;IACb,OAAO,EAAE,QAAQ,CAAC;CACnB,CAAC;IACA,WAAW,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IAE1E,oBAAoB,IAAI,cAAc,GAAG,IAAI,CAAC;CAC/C"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { IPickedCountry, PickCountryOptions } from './NitroCountryPicker.nitro';
|
|
2
|
+
export declare function pickCountry(options?: PickCountryOptions): Promise<IPickedCountry | null>;
|
|
3
|
+
export declare function getLastPickedCountry(): IPickedCountry | null;
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EAEd,kBAAkB,EACnB,MAAM,4BAA4B,CAAC;AAKpC,wBAAgB,WAAW,CACzB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAEhC;AAED,wBAAgB,oBAAoB,IAAI,cAAc,GAAG,IAAI,CAE5D"}
|
package/nitro.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"cxxNamespace": ["nitrocountrypicker"],
|
|
3
|
+
"ios": {
|
|
4
|
+
"iosModuleName": "NitroCountryPicker"
|
|
5
|
+
},
|
|
6
|
+
"android": {
|
|
7
|
+
"androidNamespace": ["nitrocountrypicker"],
|
|
8
|
+
"androidCxxLibName": "nitrocountrypicker"
|
|
9
|
+
},
|
|
10
|
+
"autolinking": {
|
|
11
|
+
"NitroCountryPicker": {
|
|
12
|
+
"ios": {
|
|
13
|
+
"language": "swift",
|
|
14
|
+
"implementationClassName": "NitroCountryPicker"
|
|
15
|
+
},
|
|
16
|
+
"android": {
|
|
17
|
+
"language": "kotlin",
|
|
18
|
+
"implementationClassName": "NitroCountryPicker"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"ignorePaths": ["node_modules"]
|
|
23
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JHybridNitroCountryPickerSpec.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 "JHybridNitroCountryPickerSpec.hpp"
|
|
9
|
+
|
|
10
|
+
// Forward declaration of `IPickedCountry` to properly resolve imports.
|
|
11
|
+
namespace margelo::nitro::nitrocountrypicker { struct IPickedCountry; }
|
|
12
|
+
// Forward declaration of `PickCountryOptions` to properly resolve imports.
|
|
13
|
+
namespace margelo::nitro::nitrocountrypicker { struct PickCountryOptions; }
|
|
14
|
+
|
|
15
|
+
#include <NitroModules/Null.hpp>
|
|
16
|
+
#include "IPickedCountry.hpp"
|
|
17
|
+
#include <variant>
|
|
18
|
+
#include <NitroModules/Promise.hpp>
|
|
19
|
+
#include <NitroModules/JPromise.hpp>
|
|
20
|
+
#include "JVariant_NullType_IPickedCountry.hpp"
|
|
21
|
+
#include <NitroModules/JNull.hpp>
|
|
22
|
+
#include "JIPickedCountry.hpp"
|
|
23
|
+
#include <string>
|
|
24
|
+
#include "PickCountryOptions.hpp"
|
|
25
|
+
#include <optional>
|
|
26
|
+
#include "JPickCountryOptions.hpp"
|
|
27
|
+
|
|
28
|
+
namespace margelo::nitro::nitrocountrypicker {
|
|
29
|
+
|
|
30
|
+
std::shared_ptr<JHybridNitroCountryPickerSpec> JHybridNitroCountryPickerSpec::JavaPart::getJHybridNitroCountryPickerSpec() {
|
|
31
|
+
auto hybridObject = JHybridObject::JavaPart::getJHybridObject();
|
|
32
|
+
auto castHybridObject = std::dynamic_pointer_cast<JHybridNitroCountryPickerSpec>(hybridObject);
|
|
33
|
+
if (castHybridObject == nullptr) [[unlikely]] {
|
|
34
|
+
throw std::runtime_error("Failed to downcast JHybridObject to JHybridNitroCountryPickerSpec!");
|
|
35
|
+
}
|
|
36
|
+
return castHybridObject;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
jni::local_ref<JHybridNitroCountryPickerSpec::CxxPart::jhybriddata> JHybridNitroCountryPickerSpec::CxxPart::initHybrid(jni::alias_ref<jhybridobject> jThis) {
|
|
40
|
+
return makeCxxInstance(jThis);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
std::shared_ptr<JHybridObject> JHybridNitroCountryPickerSpec::CxxPart::createHybridObject(const jni::local_ref<JHybridObject::JavaPart>& javaPart) {
|
|
44
|
+
auto castJavaPart = jni::dynamic_ref_cast<JHybridNitroCountryPickerSpec::JavaPart>(javaPart);
|
|
45
|
+
if (castJavaPart == nullptr) [[unlikely]] {
|
|
46
|
+
throw std::runtime_error("Failed to cast JHybridObject::JavaPart to JHybridNitroCountryPickerSpec::JavaPart!");
|
|
47
|
+
}
|
|
48
|
+
return std::make_shared<JHybridNitroCountryPickerSpec>(castJavaPart);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
void JHybridNitroCountryPickerSpec::CxxPart::registerNatives() {
|
|
52
|
+
registerHybrid({
|
|
53
|
+
makeNativeMethod("initHybrid", JHybridNitroCountryPickerSpec::CxxPart::initHybrid),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Properties
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
// Methods
|
|
61
|
+
std::shared_ptr<Promise<std::variant<nitro::NullType, IPickedCountry>>> JHybridNitroCountryPickerSpec::pickCountry(const std::optional<PickCountryOptions>& options) {
|
|
62
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<JPickCountryOptions> /* options */)>("pickCountry");
|
|
63
|
+
auto __result = method(_javaPart, options.has_value() ? JPickCountryOptions::fromCpp(options.value()) : nullptr);
|
|
64
|
+
return [&]() {
|
|
65
|
+
auto __promise = Promise<std::variant<nitro::NullType, IPickedCountry>>::create();
|
|
66
|
+
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
|
|
67
|
+
auto __result = jni::static_ref_cast<JVariant_NullType_IPickedCountry>(__boxedResult);
|
|
68
|
+
__promise->resolve(__result->toCpp());
|
|
69
|
+
});
|
|
70
|
+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
|
|
71
|
+
jni::JniException __jniError(__throwable);
|
|
72
|
+
__promise->reject(std::make_exception_ptr(__jniError));
|
|
73
|
+
});
|
|
74
|
+
return __promise;
|
|
75
|
+
}();
|
|
76
|
+
}
|
|
77
|
+
std::variant<nitro::NullType, IPickedCountry> JHybridNitroCountryPickerSpec::getLastPickedCountry() {
|
|
78
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JVariant_NullType_IPickedCountry>()>("getLastPickedCountry");
|
|
79
|
+
auto __result = method(_javaPart);
|
|
80
|
+
return __result->toCpp();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
} // namespace margelo::nitro::nitrocountrypicker
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridNitroCountryPickerSpec.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 <NitroModules/JHybridObject.hpp>
|
|
11
|
+
#include <fbjni/fbjni.h>
|
|
12
|
+
#include "HybridNitroCountryPickerSpec.hpp"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
namespace margelo::nitro::nitrocountrypicker {
|
|
18
|
+
|
|
19
|
+
using namespace facebook;
|
|
20
|
+
|
|
21
|
+
class JHybridNitroCountryPickerSpec: public virtual HybridNitroCountryPickerSpec, public virtual JHybridObject {
|
|
22
|
+
public:
|
|
23
|
+
struct JavaPart: public jni::JavaClass<JavaPart, JHybridObject::JavaPart> {
|
|
24
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitrocountrypicker/HybridNitroCountryPickerSpec;";
|
|
25
|
+
std::shared_ptr<JHybridNitroCountryPickerSpec> getJHybridNitroCountryPickerSpec();
|
|
26
|
+
};
|
|
27
|
+
struct CxxPart: public jni::HybridClass<CxxPart, JHybridObject::CxxPart> {
|
|
28
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitrocountrypicker/HybridNitroCountryPickerSpec$CxxPart;";
|
|
29
|
+
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis);
|
|
30
|
+
static void registerNatives();
|
|
31
|
+
using HybridBase::HybridBase;
|
|
32
|
+
protected:
|
|
33
|
+
std::shared_ptr<JHybridObject> createHybridObject(const jni::local_ref<JHybridObject::JavaPart>& javaPart) override;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
public:
|
|
37
|
+
explicit JHybridNitroCountryPickerSpec(const jni::local_ref<JHybridNitroCountryPickerSpec::JavaPart>& javaPart):
|
|
38
|
+
HybridObject(HybridNitroCountryPickerSpec::TAG),
|
|
39
|
+
JHybridObject(javaPart),
|
|
40
|
+
_javaPart(jni::make_global(javaPart)) {}
|
|
41
|
+
~JHybridNitroCountryPickerSpec() override {
|
|
42
|
+
// Hermes GC can destroy JS objects on a non-JNI Thread.
|
|
43
|
+
jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public:
|
|
47
|
+
inline const jni::global_ref<JHybridNitroCountryPickerSpec::JavaPart>& getJavaPart() const noexcept {
|
|
48
|
+
return _javaPart;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
// Properties
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
public:
|
|
56
|
+
// Methods
|
|
57
|
+
std::shared_ptr<Promise<std::variant<nitro::NullType, IPickedCountry>>> pickCountry(const std::optional<PickCountryOptions>& options) override;
|
|
58
|
+
std::variant<nitro::NullType, IPickedCountry> getLastPickedCountry() override;
|
|
59
|
+
|
|
60
|
+
private:
|
|
61
|
+
jni::global_ref<JHybridNitroCountryPickerSpec::JavaPart> _javaPart;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
} // namespace margelo::nitro::nitrocountrypicker
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JIPickedCountry.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 <fbjni/fbjni.h>
|
|
11
|
+
#include "IPickedCountry.hpp"
|
|
12
|
+
|
|
13
|
+
#include <string>
|
|
14
|
+
|
|
15
|
+
namespace margelo::nitro::nitrocountrypicker {
|
|
16
|
+
|
|
17
|
+
using namespace facebook;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The C++ JNI bridge between the C++ struct "IPickedCountry" and the the Kotlin data class "IPickedCountry".
|
|
21
|
+
*/
|
|
22
|
+
struct JIPickedCountry final: public jni::JavaClass<JIPickedCountry> {
|
|
23
|
+
public:
|
|
24
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitrocountrypicker/IPickedCountry;";
|
|
25
|
+
|
|
26
|
+
public:
|
|
27
|
+
/**
|
|
28
|
+
* Convert this Java/Kotlin-based struct to the C++ struct IPickedCountry by copying all values to C++.
|
|
29
|
+
*/
|
|
30
|
+
[[maybe_unused]]
|
|
31
|
+
[[nodiscard]]
|
|
32
|
+
IPickedCountry toCpp() const {
|
|
33
|
+
static const auto clazz = javaClassStatic();
|
|
34
|
+
static const auto fieldName = clazz->getField<jni::JString>("name");
|
|
35
|
+
jni::local_ref<jni::JString> name = this->getFieldValue(fieldName);
|
|
36
|
+
static const auto fieldDialCode = clazz->getField<jni::JString>("dialCode");
|
|
37
|
+
jni::local_ref<jni::JString> dialCode = this->getFieldValue(fieldDialCode);
|
|
38
|
+
static const auto fieldCode = clazz->getField<jni::JString>("code");
|
|
39
|
+
jni::local_ref<jni::JString> code = this->getFieldValue(fieldCode);
|
|
40
|
+
return IPickedCountry(
|
|
41
|
+
name->toStdString(),
|
|
42
|
+
dialCode->toStdString(),
|
|
43
|
+
code->toStdString()
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public:
|
|
48
|
+
/**
|
|
49
|
+
* Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
|
|
50
|
+
*/
|
|
51
|
+
[[maybe_unused]]
|
|
52
|
+
static jni::local_ref<JIPickedCountry::javaobject> fromCpp(const IPickedCountry& value) {
|
|
53
|
+
using JSignature = JIPickedCountry(jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>);
|
|
54
|
+
static const auto clazz = javaClassStatic();
|
|
55
|
+
static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
|
|
56
|
+
return create(
|
|
57
|
+
clazz,
|
|
58
|
+
jni::make_jstring(value.name),
|
|
59
|
+
jni::make_jstring(value.dialCode),
|
|
60
|
+
jni::make_jstring(value.code)
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
} // namespace margelo::nitro::nitrocountrypicker
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JPickCountryOptions.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 <fbjni/fbjni.h>
|
|
11
|
+
#include "PickCountryOptions.hpp"
|
|
12
|
+
|
|
13
|
+
#include <optional>
|
|
14
|
+
#include <string>
|
|
15
|
+
|
|
16
|
+
namespace margelo::nitro::nitrocountrypicker {
|
|
17
|
+
|
|
18
|
+
using namespace facebook;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The C++ JNI bridge between the C++ struct "PickCountryOptions" and the the Kotlin data class "PickCountryOptions".
|
|
22
|
+
*/
|
|
23
|
+
struct JPickCountryOptions final: public jni::JavaClass<JPickCountryOptions> {
|
|
24
|
+
public:
|
|
25
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitrocountrypicker/PickCountryOptions;";
|
|
26
|
+
|
|
27
|
+
public:
|
|
28
|
+
/**
|
|
29
|
+
* Convert this Java/Kotlin-based struct to the C++ struct PickCountryOptions by copying all values to C++.
|
|
30
|
+
*/
|
|
31
|
+
[[maybe_unused]]
|
|
32
|
+
[[nodiscard]]
|
|
33
|
+
PickCountryOptions toCpp() const {
|
|
34
|
+
static const auto clazz = javaClassStatic();
|
|
35
|
+
static const auto fieldHeaderTitle = clazz->getField<jni::JString>("headerTitle");
|
|
36
|
+
jni::local_ref<jni::JString> headerTitle = this->getFieldValue(fieldHeaderTitle);
|
|
37
|
+
return PickCountryOptions(
|
|
38
|
+
headerTitle != nullptr ? std::make_optional(headerTitle->toStdString()) : std::nullopt
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public:
|
|
43
|
+
/**
|
|
44
|
+
* Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
|
|
45
|
+
*/
|
|
46
|
+
[[maybe_unused]]
|
|
47
|
+
static jni::local_ref<JPickCountryOptions::javaobject> fromCpp(const PickCountryOptions& value) {
|
|
48
|
+
using JSignature = JPickCountryOptions(jni::alias_ref<jni::JString>);
|
|
49
|
+
static const auto clazz = javaClassStatic();
|
|
50
|
+
static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
|
|
51
|
+
return create(
|
|
52
|
+
clazz,
|
|
53
|
+
value.headerTitle.has_value() ? jni::make_jstring(value.headerTitle.value()) : nullptr
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
} // namespace margelo::nitro::nitrocountrypicker
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JVariant_NullType_IPickedCountry.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 "JVariant_NullType_IPickedCountry.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::nitrocountrypicker {
|
|
11
|
+
/**
|
|
12
|
+
* Converts JVariant_NullType_IPickedCountry to std::variant<nitro::NullType, IPickedCountry>
|
|
13
|
+
*/
|
|
14
|
+
std::variant<nitro::NullType, IPickedCountry> JVariant_NullType_IPickedCountry::toCpp() const {
|
|
15
|
+
if (isInstanceOf(JVariant_NullType_IPickedCountry_impl::First::javaClassStatic())) {
|
|
16
|
+
// It's a `nitro::NullType`
|
|
17
|
+
auto jniValue = static_cast<const JVariant_NullType_IPickedCountry_impl::First*>(this)->getValue();
|
|
18
|
+
return nitro::null;
|
|
19
|
+
} else if (isInstanceOf(JVariant_NullType_IPickedCountry_impl::Second::javaClassStatic())) {
|
|
20
|
+
// It's a `IPickedCountry`
|
|
21
|
+
auto jniValue = static_cast<const JVariant_NullType_IPickedCountry_impl::Second*>(this)->getValue();
|
|
22
|
+
return jniValue->toCpp();
|
|
23
|
+
}
|
|
24
|
+
throw std::invalid_argument("Variant is unknown Kotlin instance!");
|
|
25
|
+
}
|
|
26
|
+
} // namespace margelo::nitro::nitrocountrypicker
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JVariant_NullType_IPickedCountry.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 <fbjni/fbjni.h>
|
|
11
|
+
#include <variant>
|
|
12
|
+
|
|
13
|
+
#include <NitroModules/Null.hpp>
|
|
14
|
+
#include "IPickedCountry.hpp"
|
|
15
|
+
#include <variant>
|
|
16
|
+
#include <NitroModules/JNull.hpp>
|
|
17
|
+
#include "JIPickedCountry.hpp"
|
|
18
|
+
#include <string>
|
|
19
|
+
|
|
20
|
+
namespace margelo::nitro::nitrocountrypicker {
|
|
21
|
+
|
|
22
|
+
using namespace facebook;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The C++ JNI bridge between the C++ std::variant and the Java class "Variant_NullType_IPickedCountry".
|
|
26
|
+
*/
|
|
27
|
+
class JVariant_NullType_IPickedCountry: public jni::JavaClass<JVariant_NullType_IPickedCountry> {
|
|
28
|
+
public:
|
|
29
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitrocountrypicker/Variant_NullType_IPickedCountry;";
|
|
30
|
+
|
|
31
|
+
static jni::local_ref<JVariant_NullType_IPickedCountry> create_0(jni::alias_ref<JNull> value) {
|
|
32
|
+
static const auto method = javaClassStatic()->getStaticMethod<JVariant_NullType_IPickedCountry(jni::alias_ref<JNull>)>("create");
|
|
33
|
+
return method(javaClassStatic(), value);
|
|
34
|
+
}
|
|
35
|
+
static jni::local_ref<JVariant_NullType_IPickedCountry> create_1(jni::alias_ref<JIPickedCountry> value) {
|
|
36
|
+
static const auto method = javaClassStatic()->getStaticMethod<JVariant_NullType_IPickedCountry(jni::alias_ref<JIPickedCountry>)>("create");
|
|
37
|
+
return method(javaClassStatic(), value);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static jni::local_ref<JVariant_NullType_IPickedCountry> fromCpp(const std::variant<nitro::NullType, IPickedCountry>& variant) {
|
|
41
|
+
switch (variant.index()) {
|
|
42
|
+
case 0: return create_0(JNull::null());
|
|
43
|
+
case 1: return create_1(JIPickedCountry::fromCpp(std::get<1>(variant)));
|
|
44
|
+
default: throw std::invalid_argument("Variant holds unknown index! (" + std::to_string(variant.index()) + ")");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
[[nodiscard]] std::variant<nitro::NullType, IPickedCountry> toCpp() const;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
namespace JVariant_NullType_IPickedCountry_impl {
|
|
52
|
+
class First final: public jni::JavaClass<First, JVariant_NullType_IPickedCountry> {
|
|
53
|
+
public:
|
|
54
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitrocountrypicker/Variant_NullType_IPickedCountry$First;";
|
|
55
|
+
|
|
56
|
+
[[nodiscard]] jni::local_ref<JNull> getValue() const {
|
|
57
|
+
static const auto field = javaClassStatic()->getField<JNull>("value");
|
|
58
|
+
return getFieldValue(field);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
class Second final: public jni::JavaClass<Second, JVariant_NullType_IPickedCountry> {
|
|
63
|
+
public:
|
|
64
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitrocountrypicker/Variant_NullType_IPickedCountry$Second;";
|
|
65
|
+
|
|
66
|
+
[[nodiscard]] jni::local_ref<JIPickedCountry> getValue() const {
|
|
67
|
+
static const auto field = javaClassStatic()->getField<JIPickedCountry>("value");
|
|
68
|
+
return getFieldValue(field);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
} // namespace JVariant_NullType_IPickedCountry_impl
|
|
72
|
+
} // namespace margelo::nitro::nitrocountrypicker
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridNitroCountryPickerSpec.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.nitrocountrypicker
|
|
9
|
+
|
|
10
|
+
import androidx.annotation.Keep
|
|
11
|
+
import com.facebook.jni.HybridData
|
|
12
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
13
|
+
import com.margelo.nitro.core.NullType
|
|
14
|
+
import com.margelo.nitro.core.Promise
|
|
15
|
+
import com.margelo.nitro.core.HybridObject
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A Kotlin class representing the NitroCountryPicker HybridObject.
|
|
19
|
+
* Implement this abstract class to create Kotlin-based instances of NitroCountryPicker.
|
|
20
|
+
*/
|
|
21
|
+
@DoNotStrip
|
|
22
|
+
@Keep
|
|
23
|
+
@Suppress(
|
|
24
|
+
"KotlinJniMissingFunction", "unused",
|
|
25
|
+
"RedundantSuppression", "RedundantUnitReturnType", "SimpleRedundantLet",
|
|
26
|
+
"LocalVariableName", "PropertyName", "PrivatePropertyName", "FunctionName"
|
|
27
|
+
)
|
|
28
|
+
abstract class HybridNitroCountryPickerSpec: HybridObject() {
|
|
29
|
+
// Properties
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
// Methods
|
|
33
|
+
@DoNotStrip
|
|
34
|
+
@Keep
|
|
35
|
+
abstract fun pickCountry(options: PickCountryOptions?): Promise<Variant_NullType_IPickedCountry>
|
|
36
|
+
|
|
37
|
+
@DoNotStrip
|
|
38
|
+
@Keep
|
|
39
|
+
abstract fun getLastPickedCountry(): Variant_NullType_IPickedCountry
|
|
40
|
+
|
|
41
|
+
// Default implementation of `HybridObject.toString()`
|
|
42
|
+
override fun toString(): String {
|
|
43
|
+
return "[HybridObject NitroCountryPicker]"
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// C++ backing class
|
|
47
|
+
@DoNotStrip
|
|
48
|
+
@Keep
|
|
49
|
+
protected open class CxxPart(javaPart: HybridNitroCountryPickerSpec): HybridObject.CxxPart(javaPart) {
|
|
50
|
+
// C++ JHybridNitroCountryPickerSpec::CxxPart::initHybrid(...)
|
|
51
|
+
external override fun initHybrid(): HybridData
|
|
52
|
+
}
|
|
53
|
+
override fun createCxxPart(): CxxPart {
|
|
54
|
+
return CxxPart(this)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
companion object {
|
|
58
|
+
protected const val TAG = "HybridNitroCountryPickerSpec"
|
|
59
|
+
}
|
|
60
|
+
}
|
package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocountrypicker/IPickedCountry.kt
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// IPickedCountry.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.nitrocountrypicker
|
|
9
|
+
|
|
10
|
+
import androidx.annotation.Keep
|
|
11
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Represents the JavaScript object/struct "IPickedCountry".
|
|
16
|
+
*/
|
|
17
|
+
@DoNotStrip
|
|
18
|
+
@Keep
|
|
19
|
+
data class IPickedCountry(
|
|
20
|
+
@DoNotStrip
|
|
21
|
+
@Keep
|
|
22
|
+
val name: String,
|
|
23
|
+
@DoNotStrip
|
|
24
|
+
@Keep
|
|
25
|
+
val dialCode: String,
|
|
26
|
+
@DoNotStrip
|
|
27
|
+
@Keep
|
|
28
|
+
val code: String
|
|
29
|
+
) {
|
|
30
|
+
/* primary constructor */
|
|
31
|
+
|
|
32
|
+
companion object {
|
|
33
|
+
/**
|
|
34
|
+
* Constructor called from C++
|
|
35
|
+
*/
|
|
36
|
+
@DoNotStrip
|
|
37
|
+
@Keep
|
|
38
|
+
@Suppress("unused")
|
|
39
|
+
@JvmStatic
|
|
40
|
+
private fun fromCpp(name: String, dialCode: String, code: String): IPickedCountry {
|
|
41
|
+
return IPickedCountry(name, dialCode, code)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|