@onekeyfe/react-native-scroll-guard 0.1.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.
- package/ScrollGuard.podspec +29 -0
- package/android/CMakeLists.txt +24 -0
- package/android/build.gradle +124 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/cpp-adapter.cpp +6 -0
- package/android/src/main/java/com/margelo/nitro/scrollguard/ScrollGuard.kt +117 -0
- package/android/src/main/java/com/margelo/nitro/scrollguard/ScrollGuardPackage.kt +27 -0
- package/android/src/main/java/com/margelo/nitro/scrollguard/ScrollGuardViewGroupManager.kt +48 -0
- package/ios/ScrollGuard.swift +243 -0
- package/lib/module/ScrollGuard.nitro.js +9 -0
- package/lib/module/ScrollGuard.nitro.js.map +1 -0
- package/lib/module/index.js +7 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/nitrogen/generated/android/c++/JHybridScrollGuardSpec.cpp +59 -0
- package/lib/nitrogen/generated/android/c++/JHybridScrollGuardSpec.hpp +66 -0
- package/lib/nitrogen/generated/android/c++/JScrollGuardDirection.hpp +62 -0
- package/lib/nitrogen/generated/android/c++/views/JHybridScrollGuardStateUpdater.cpp +56 -0
- package/lib/nitrogen/generated/android/c++/views/JHybridScrollGuardStateUpdater.hpp +49 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/scrollguard/HybridScrollGuardSpec.kt +59 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/scrollguard/ScrollGuardDirection.kt +22 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/scrollguard/scrollguardOnLoad.kt +35 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/scrollguard/views/HybridScrollGuardManager.kt +50 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/scrollguard/views/HybridScrollGuardStateUpdater.kt +23 -0
- package/lib/nitrogen/generated/android/scrollguard+autolinking.cmake +83 -0
- package/lib/nitrogen/generated/android/scrollguard+autolinking.gradle +27 -0
- package/lib/nitrogen/generated/android/scrollguardOnLoad.cpp +46 -0
- package/lib/nitrogen/generated/android/scrollguardOnLoad.hpp +25 -0
- package/lib/nitrogen/generated/ios/ScrollGuard+autolinking.rb +60 -0
- package/lib/nitrogen/generated/ios/ScrollGuard-Swift-Cxx-Bridge.cpp +33 -0
- package/lib/nitrogen/generated/ios/ScrollGuard-Swift-Cxx-Bridge.hpp +59 -0
- package/lib/nitrogen/generated/ios/ScrollGuard-Swift-Cxx-Umbrella.hpp +45 -0
- package/lib/nitrogen/generated/ios/ScrollGuardAutolinking.mm +33 -0
- package/lib/nitrogen/generated/ios/ScrollGuardAutolinking.swift +25 -0
- package/lib/nitrogen/generated/ios/c++/HybridScrollGuardSpecSwift.cpp +11 -0
- package/lib/nitrogen/generated/ios/c++/HybridScrollGuardSpecSwift.hpp +77 -0
- package/lib/nitrogen/generated/ios/c++/views/HybridScrollGuardComponent.mm +96 -0
- package/lib/nitrogen/generated/ios/swift/HybridScrollGuardSpec.swift +56 -0
- package/lib/nitrogen/generated/ios/swift/HybridScrollGuardSpec_cxx.swift +146 -0
- package/lib/nitrogen/generated/ios/swift/ScrollGuardDirection.swift +44 -0
- package/lib/nitrogen/generated/shared/c++/HybridScrollGuardSpec.cpp +22 -0
- package/lib/nitrogen/generated/shared/c++/HybridScrollGuardSpec.hpp +65 -0
- package/lib/nitrogen/generated/shared/c++/ScrollGuardDirection.hpp +80 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridScrollGuardComponent.cpp +87 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridScrollGuardComponent.hpp +108 -0
- package/lib/nitrogen/generated/shared/json/ScrollGuardConfig.json +10 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/ScrollGuard.nitro.d.ts +19 -0
- package/lib/typescript/src/ScrollGuard.nitro.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +5 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/nitro.json +17 -0
- package/nitrogen/generated/android/c++/JHybridScrollGuardSpec.cpp +59 -0
- package/nitrogen/generated/android/c++/JHybridScrollGuardSpec.hpp +66 -0
- package/nitrogen/generated/android/c++/JScrollGuardDirection.hpp +62 -0
- package/nitrogen/generated/android/c++/views/JHybridScrollGuardStateUpdater.cpp +56 -0
- package/nitrogen/generated/android/c++/views/JHybridScrollGuardStateUpdater.hpp +49 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/scrollguard/HybridScrollGuardSpec.kt +59 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/scrollguard/ScrollGuardDirection.kt +22 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/scrollguard/scrollguardOnLoad.kt +35 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/scrollguard/views/HybridScrollGuardManager.kt +50 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/scrollguard/views/HybridScrollGuardStateUpdater.kt +23 -0
- package/nitrogen/generated/android/scrollguard+autolinking.cmake +83 -0
- package/nitrogen/generated/android/scrollguard+autolinking.gradle +27 -0
- package/nitrogen/generated/android/scrollguardOnLoad.cpp +46 -0
- package/nitrogen/generated/android/scrollguardOnLoad.hpp +25 -0
- package/nitrogen/generated/ios/ScrollGuard+autolinking.rb +60 -0
- package/nitrogen/generated/ios/ScrollGuard-Swift-Cxx-Bridge.cpp +33 -0
- package/nitrogen/generated/ios/ScrollGuard-Swift-Cxx-Bridge.hpp +59 -0
- package/nitrogen/generated/ios/ScrollGuard-Swift-Cxx-Umbrella.hpp +45 -0
- package/nitrogen/generated/ios/ScrollGuardAutolinking.mm +33 -0
- package/nitrogen/generated/ios/ScrollGuardAutolinking.swift +25 -0
- package/nitrogen/generated/ios/c++/HybridScrollGuardSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridScrollGuardSpecSwift.hpp +77 -0
- package/nitrogen/generated/ios/c++/views/HybridScrollGuardComponent.mm +96 -0
- package/nitrogen/generated/ios/swift/HybridScrollGuardSpec.swift +56 -0
- package/nitrogen/generated/ios/swift/HybridScrollGuardSpec_cxx.swift +146 -0
- package/nitrogen/generated/ios/swift/ScrollGuardDirection.swift +44 -0
- package/nitrogen/generated/shared/c++/HybridScrollGuardSpec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridScrollGuardSpec.hpp +65 -0
- package/nitrogen/generated/shared/c++/ScrollGuardDirection.hpp +80 -0
- package/nitrogen/generated/shared/c++/views/HybridScrollGuardComponent.cpp +87 -0
- package/nitrogen/generated/shared/c++/views/HybridScrollGuardComponent.hpp +108 -0
- package/nitrogen/generated/shared/json/ScrollGuardConfig.json +10 -0
- package/package.json +106 -0
- package/src/ScrollGuard.nitro.ts +25 -0
- package/src/index.tsx +11 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// ScrollGuardDirection.swift
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Represents the JS union `ScrollGuardDirection`, backed by a C++ enum.
|
|
10
|
+
*/
|
|
11
|
+
public typealias ScrollGuardDirection = margelo.nitro.scrollguard.ScrollGuardDirection
|
|
12
|
+
|
|
13
|
+
public extension ScrollGuardDirection {
|
|
14
|
+
/**
|
|
15
|
+
* Get a ScrollGuardDirection 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 "horizontal":
|
|
21
|
+
self = .horizontal
|
|
22
|
+
case "vertical":
|
|
23
|
+
self = .vertical
|
|
24
|
+
case "both":
|
|
25
|
+
self = .both
|
|
26
|
+
default:
|
|
27
|
+
return nil
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Get the String value this ScrollGuardDirection represents.
|
|
33
|
+
*/
|
|
34
|
+
var stringValue: String {
|
|
35
|
+
switch self {
|
|
36
|
+
case .horizontal:
|
|
37
|
+
return "horizontal"
|
|
38
|
+
case .vertical:
|
|
39
|
+
return "vertical"
|
|
40
|
+
case .both:
|
|
41
|
+
return "both"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridScrollGuardSpec.cpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#include "HybridScrollGuardSpec.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::scrollguard {
|
|
11
|
+
|
|
12
|
+
void HybridScrollGuardSpec::loadHybridMethods() {
|
|
13
|
+
// load base methods/properties
|
|
14
|
+
HybridObject::loadHybridMethods();
|
|
15
|
+
// load custom methods/properties
|
|
16
|
+
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
+
prototype.registerHybridGetter("direction", &HybridScrollGuardSpec::getDirection);
|
|
18
|
+
prototype.registerHybridSetter("direction", &HybridScrollGuardSpec::setDirection);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
} // namespace margelo::nitro::scrollguard
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridScrollGuardSpec.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 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 `ScrollGuardDirection` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::scrollguard { enum class ScrollGuardDirection; }
|
|
18
|
+
|
|
19
|
+
#include "ScrollGuardDirection.hpp"
|
|
20
|
+
#include <optional>
|
|
21
|
+
|
|
22
|
+
namespace margelo::nitro::scrollguard {
|
|
23
|
+
|
|
24
|
+
using namespace margelo::nitro;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* An abstract base class for `ScrollGuard`
|
|
28
|
+
* Inherit this class to create instances of `HybridScrollGuardSpec` in C++.
|
|
29
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
30
|
+
* @example
|
|
31
|
+
* ```cpp
|
|
32
|
+
* class HybridScrollGuard: public HybridScrollGuardSpec {
|
|
33
|
+
* public:
|
|
34
|
+
* HybridScrollGuard(...): HybridObject(TAG) { ... }
|
|
35
|
+
* // ...
|
|
36
|
+
* };
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
class HybridScrollGuardSpec: public virtual HybridObject {
|
|
40
|
+
public:
|
|
41
|
+
// Constructor
|
|
42
|
+
explicit HybridScrollGuardSpec(): HybridObject(TAG) { }
|
|
43
|
+
|
|
44
|
+
// Destructor
|
|
45
|
+
~HybridScrollGuardSpec() override = default;
|
|
46
|
+
|
|
47
|
+
public:
|
|
48
|
+
// Properties
|
|
49
|
+
virtual std::optional<ScrollGuardDirection> getDirection() = 0;
|
|
50
|
+
virtual void setDirection(std::optional<ScrollGuardDirection> direction) = 0;
|
|
51
|
+
|
|
52
|
+
public:
|
|
53
|
+
// Methods
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
protected:
|
|
57
|
+
// Hybrid Setup
|
|
58
|
+
void loadHybridMethods() override;
|
|
59
|
+
|
|
60
|
+
protected:
|
|
61
|
+
// Tag for logging
|
|
62
|
+
static constexpr auto TAG = "ScrollGuard";
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
} // namespace margelo::nitro::scrollguard
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// ScrollGuardDirection.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/NitroHash.hpp>)
|
|
11
|
+
#include <NitroModules/NitroHash.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
16
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
21
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
namespace margelo::nitro::scrollguard {
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* An enum which can be represented as a JavaScript union (ScrollGuardDirection).
|
|
30
|
+
*/
|
|
31
|
+
enum class ScrollGuardDirection {
|
|
32
|
+
HORIZONTAL SWIFT_NAME(horizontal) = 0,
|
|
33
|
+
VERTICAL SWIFT_NAME(vertical) = 1,
|
|
34
|
+
BOTH SWIFT_NAME(both) = 2,
|
|
35
|
+
} CLOSED_ENUM;
|
|
36
|
+
|
|
37
|
+
} // namespace margelo::nitro::scrollguard
|
|
38
|
+
|
|
39
|
+
namespace margelo::nitro {
|
|
40
|
+
|
|
41
|
+
// C++ ScrollGuardDirection <> JS ScrollGuardDirection (union)
|
|
42
|
+
template <>
|
|
43
|
+
struct JSIConverter<margelo::nitro::scrollguard::ScrollGuardDirection> final {
|
|
44
|
+
static inline margelo::nitro::scrollguard::ScrollGuardDirection fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
45
|
+
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
|
|
46
|
+
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
47
|
+
case hashString("horizontal"): return margelo::nitro::scrollguard::ScrollGuardDirection::HORIZONTAL;
|
|
48
|
+
case hashString("vertical"): return margelo::nitro::scrollguard::ScrollGuardDirection::VERTICAL;
|
|
49
|
+
case hashString("both"): return margelo::nitro::scrollguard::ScrollGuardDirection::BOTH;
|
|
50
|
+
default: [[unlikely]]
|
|
51
|
+
throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum ScrollGuardDirection - invalid value!");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::scrollguard::ScrollGuardDirection arg) {
|
|
55
|
+
switch (arg) {
|
|
56
|
+
case margelo::nitro::scrollguard::ScrollGuardDirection::HORIZONTAL: return JSIConverter<std::string>::toJSI(runtime, "horizontal");
|
|
57
|
+
case margelo::nitro::scrollguard::ScrollGuardDirection::VERTICAL: return JSIConverter<std::string>::toJSI(runtime, "vertical");
|
|
58
|
+
case margelo::nitro::scrollguard::ScrollGuardDirection::BOTH: return JSIConverter<std::string>::toJSI(runtime, "both");
|
|
59
|
+
default: [[unlikely]]
|
|
60
|
+
throw std::invalid_argument("Cannot convert ScrollGuardDirection to JS - invalid value: "
|
|
61
|
+
+ std::to_string(static_cast<int>(arg)) + "!");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
65
|
+
if (!value.isString()) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
|
|
69
|
+
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
70
|
+
case hashString("horizontal"):
|
|
71
|
+
case hashString("vertical"):
|
|
72
|
+
case hashString("both"):
|
|
73
|
+
return true;
|
|
74
|
+
default:
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridScrollGuardComponent.cpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#include "HybridScrollGuardComponent.hpp"
|
|
9
|
+
|
|
10
|
+
#include <string>
|
|
11
|
+
#include <exception>
|
|
12
|
+
#include <utility>
|
|
13
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
14
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
15
|
+
#include <react/renderer/core/RawValue.h>
|
|
16
|
+
#include <react/renderer/core/ShadowNode.h>
|
|
17
|
+
#include <react/renderer/core/ComponentDescriptor.h>
|
|
18
|
+
#include <react/renderer/components/view/ViewProps.h>
|
|
19
|
+
|
|
20
|
+
namespace margelo::nitro::scrollguard::views {
|
|
21
|
+
|
|
22
|
+
extern const char HybridScrollGuardComponentName[] = "ScrollGuard";
|
|
23
|
+
|
|
24
|
+
HybridScrollGuardProps::HybridScrollGuardProps(const react::PropsParserContext& context,
|
|
25
|
+
const HybridScrollGuardProps& sourceProps,
|
|
26
|
+
const react::RawProps& rawProps):
|
|
27
|
+
react::ViewProps(context, sourceProps, rawProps, filterObjectKeys),
|
|
28
|
+
direction([&]() -> CachedProp<std::optional<ScrollGuardDirection>> {
|
|
29
|
+
try {
|
|
30
|
+
const react::RawValue* rawValue = rawProps.at("direction", nullptr, nullptr);
|
|
31
|
+
if (rawValue == nullptr) return sourceProps.direction;
|
|
32
|
+
const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
|
|
33
|
+
return CachedProp<std::optional<ScrollGuardDirection>>::fromRawValue(*runtime, value, sourceProps.direction);
|
|
34
|
+
} catch (const std::exception& exc) {
|
|
35
|
+
throw std::runtime_error(std::string("ScrollGuard.direction: ") + exc.what());
|
|
36
|
+
}
|
|
37
|
+
}()),
|
|
38
|
+
hybridRef([&]() -> CachedProp<std::optional<std::function<void(const std::shared_ptr<HybridScrollGuardSpec>& /* ref */)>>> {
|
|
39
|
+
try {
|
|
40
|
+
const react::RawValue* rawValue = rawProps.at("hybridRef", nullptr, nullptr);
|
|
41
|
+
if (rawValue == nullptr) return sourceProps.hybridRef;
|
|
42
|
+
const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
|
|
43
|
+
return CachedProp<std::optional<std::function<void(const std::shared_ptr<HybridScrollGuardSpec>& /* ref */)>>>::fromRawValue(*runtime, value.asObject(*runtime).getProperty(*runtime, "f"), sourceProps.hybridRef);
|
|
44
|
+
} catch (const std::exception& exc) {
|
|
45
|
+
throw std::runtime_error(std::string("ScrollGuard.hybridRef: ") + exc.what());
|
|
46
|
+
}
|
|
47
|
+
}()) { }
|
|
48
|
+
|
|
49
|
+
HybridScrollGuardProps::HybridScrollGuardProps(const HybridScrollGuardProps& other):
|
|
50
|
+
react::ViewProps(),
|
|
51
|
+
direction(other.direction),
|
|
52
|
+
hybridRef(other.hybridRef) { }
|
|
53
|
+
|
|
54
|
+
bool HybridScrollGuardProps::filterObjectKeys(const std::string& propName) {
|
|
55
|
+
switch (hashString(propName)) {
|
|
56
|
+
case hashString("direction"): return true;
|
|
57
|
+
case hashString("hybridRef"): return true;
|
|
58
|
+
default: return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
HybridScrollGuardComponentDescriptor::HybridScrollGuardComponentDescriptor(const react::ComponentDescriptorParameters& parameters)
|
|
63
|
+
: ConcreteComponentDescriptor(parameters,
|
|
64
|
+
react::RawPropsParser(/* enableJsiParser */ true)) {}
|
|
65
|
+
|
|
66
|
+
std::shared_ptr<const react::Props> HybridScrollGuardComponentDescriptor::cloneProps(const react::PropsParserContext& context,
|
|
67
|
+
const std::shared_ptr<const react::Props>& props,
|
|
68
|
+
react::RawProps rawProps) const {
|
|
69
|
+
// 1. Prepare raw props parser
|
|
70
|
+
rawProps.parse(rawPropsParser_);
|
|
71
|
+
// 2. Copy props with Nitro's cached copy constructor
|
|
72
|
+
return HybridScrollGuardShadowNode::Props(context, /* & */ rawProps, props);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
#ifdef ANDROID
|
|
76
|
+
void HybridScrollGuardComponentDescriptor::adopt(react::ShadowNode& shadowNode) const {
|
|
77
|
+
// This is called immediately after `ShadowNode` is created, cloned or in progress.
|
|
78
|
+
// On Android, we need to wrap props in our state, which gets routed through Java and later unwrapped in JNI/C++.
|
|
79
|
+
auto& concreteShadowNode = dynamic_cast<HybridScrollGuardShadowNode&>(shadowNode);
|
|
80
|
+
const HybridScrollGuardProps& props = concreteShadowNode.getConcreteProps();
|
|
81
|
+
HybridScrollGuardState state;
|
|
82
|
+
state.setProps(props);
|
|
83
|
+
concreteShadowNode.setStateData(std::move(state));
|
|
84
|
+
}
|
|
85
|
+
#endif
|
|
86
|
+
|
|
87
|
+
} // namespace margelo::nitro::scrollguard::views
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridScrollGuardComponent.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include <optional>
|
|
11
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
12
|
+
#include <NitroModules/NitroHash.hpp>
|
|
13
|
+
#include <NitroModules/CachedProp.hpp>
|
|
14
|
+
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
|
15
|
+
#include <react/renderer/core/PropsParserContext.h>
|
|
16
|
+
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
|
17
|
+
#include <react/renderer/components/view/ViewProps.h>
|
|
18
|
+
|
|
19
|
+
#include "ScrollGuardDirection.hpp"
|
|
20
|
+
#include <optional>
|
|
21
|
+
#include <memory>
|
|
22
|
+
#include "HybridScrollGuardSpec.hpp"
|
|
23
|
+
#include <functional>
|
|
24
|
+
|
|
25
|
+
namespace margelo::nitro::scrollguard::views {
|
|
26
|
+
|
|
27
|
+
using namespace facebook;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The name of the actual native View.
|
|
31
|
+
*/
|
|
32
|
+
extern const char HybridScrollGuardComponentName[];
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Props for the "ScrollGuard" View.
|
|
36
|
+
*/
|
|
37
|
+
class HybridScrollGuardProps final: public react::ViewProps {
|
|
38
|
+
public:
|
|
39
|
+
HybridScrollGuardProps() = default;
|
|
40
|
+
HybridScrollGuardProps(const HybridScrollGuardProps&);
|
|
41
|
+
HybridScrollGuardProps(const react::PropsParserContext& context,
|
|
42
|
+
const HybridScrollGuardProps& sourceProps,
|
|
43
|
+
const react::RawProps& rawProps);
|
|
44
|
+
|
|
45
|
+
public:
|
|
46
|
+
CachedProp<std::optional<ScrollGuardDirection>> direction;
|
|
47
|
+
CachedProp<std::optional<std::function<void(const std::shared_ptr<HybridScrollGuardSpec>& /* ref */)>>> hybridRef;
|
|
48
|
+
|
|
49
|
+
private:
|
|
50
|
+
static bool filterObjectKeys(const std::string& propName);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* State for the "ScrollGuard" View.
|
|
55
|
+
*/
|
|
56
|
+
class HybridScrollGuardState final {
|
|
57
|
+
public:
|
|
58
|
+
HybridScrollGuardState() = default;
|
|
59
|
+
|
|
60
|
+
public:
|
|
61
|
+
void setProps(const HybridScrollGuardProps& props) { _props.emplace(props); }
|
|
62
|
+
const std::optional<HybridScrollGuardProps>& getProps() const { return _props; }
|
|
63
|
+
|
|
64
|
+
public:
|
|
65
|
+
#ifdef ANDROID
|
|
66
|
+
HybridScrollGuardState(const HybridScrollGuardState& /* previousState */, folly::dynamic /* data */) {}
|
|
67
|
+
folly::dynamic getDynamic() const {
|
|
68
|
+
throw std::runtime_error("HybridScrollGuardState does not support folly!");
|
|
69
|
+
}
|
|
70
|
+
react::MapBuffer getMapBuffer() const {
|
|
71
|
+
throw std::runtime_error("HybridScrollGuardState does not support MapBuffer!");
|
|
72
|
+
};
|
|
73
|
+
#endif
|
|
74
|
+
|
|
75
|
+
private:
|
|
76
|
+
std::optional<HybridScrollGuardProps> _props;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The Shadow Node for the "ScrollGuard" View.
|
|
81
|
+
*/
|
|
82
|
+
using HybridScrollGuardShadowNode = react::ConcreteViewShadowNode<HybridScrollGuardComponentName /* "HybridScrollGuard" */,
|
|
83
|
+
HybridScrollGuardProps /* custom props */,
|
|
84
|
+
react::ViewEventEmitter /* default */,
|
|
85
|
+
HybridScrollGuardState /* custom state */>;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The Component Descriptor for the "ScrollGuard" View.
|
|
89
|
+
*/
|
|
90
|
+
class HybridScrollGuardComponentDescriptor final: public react::ConcreteComponentDescriptor<HybridScrollGuardShadowNode> {
|
|
91
|
+
public:
|
|
92
|
+
HybridScrollGuardComponentDescriptor(const react::ComponentDescriptorParameters& parameters);
|
|
93
|
+
|
|
94
|
+
public:
|
|
95
|
+
/**
|
|
96
|
+
* A faster path for cloning props - reuses the caching logic from `HybridScrollGuardProps`.
|
|
97
|
+
*/
|
|
98
|
+
std::shared_ptr<const react::Props> cloneProps(const react::PropsParserContext& context,
|
|
99
|
+
const std::shared_ptr<const react::Props>& props,
|
|
100
|
+
react::RawProps rawProps) const override;
|
|
101
|
+
#ifdef ANDROID
|
|
102
|
+
void adopt(react::ShadowNode& shadowNode) const override;
|
|
103
|
+
#endif
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/* The actual view for "ScrollGuard" needs to be implemented in platform-specific code. */
|
|
107
|
+
|
|
108
|
+
} // namespace margelo::nitro::scrollguard::views
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { HybridView, HybridViewMethods, HybridViewProps } from 'react-native-nitro-modules';
|
|
2
|
+
export declare enum ScrollGuardDirection {
|
|
3
|
+
HORIZONTAL = "horizontal",
|
|
4
|
+
VERTICAL = "vertical",
|
|
5
|
+
BOTH = "both"
|
|
6
|
+
}
|
|
7
|
+
export interface ScrollGuardProps extends HybridViewProps {
|
|
8
|
+
/**
|
|
9
|
+
* The scroll direction to guard.
|
|
10
|
+
* - HORIZONTAL: block parent from intercepting horizontal gestures (default)
|
|
11
|
+
* - VERTICAL: block parent from intercepting vertical gestures
|
|
12
|
+
* - BOTH: block both directions
|
|
13
|
+
*/
|
|
14
|
+
direction?: ScrollGuardDirection;
|
|
15
|
+
}
|
|
16
|
+
export interface ScrollGuardMethods extends HybridViewMethods {
|
|
17
|
+
}
|
|
18
|
+
export type ScrollGuard = HybridView<ScrollGuardProps, ScrollGuardMethods>;
|
|
19
|
+
//# sourceMappingURL=ScrollGuard.nitro.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScrollGuard.nitro.d.ts","sourceRoot":"","sources":["../../../src/ScrollGuard.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,iBAAiB,EACjB,eAAe,EAChB,MAAM,4BAA4B,CAAC;AAEpC,oBAAY,oBAAoB;IAC9B,UAAU,eAAe;IACzB,QAAQ,aAAa;IACrB,IAAI,SAAS;CACd;AAED,MAAM,WAAW,gBAAiB,SAAQ,eAAe;IACvD;;;;;OAKG;IACH,SAAS,CAAC,EAAE,oBAAoB,CAAC;CAClC;AAED,MAAM,WAAW,kBAAmB,SAAQ,iBAAiB;CAAG;AAEhE,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ScrollGuardMethods, ScrollGuardProps } from './ScrollGuard.nitro';
|
|
2
|
+
export { ScrollGuardDirection } from './ScrollGuard.nitro';
|
|
3
|
+
export declare const ScrollGuardView: import("react-native-nitro-modules").ReactNativeView<ScrollGuardProps, ScrollGuardMethods>;
|
|
4
|
+
export type { ScrollGuardProps, ScrollGuardMethods };
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAE3D,eAAO,MAAM,eAAe,4FAGa,CAAC;AAE1C,YAAY,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,CAAC"}
|
package/nitro.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"cxxNamespace": ["scrollguard"],
|
|
3
|
+
"ios": {
|
|
4
|
+
"iosModuleName": "ScrollGuard"
|
|
5
|
+
},
|
|
6
|
+
"android": {
|
|
7
|
+
"androidNamespace": ["scrollguard"],
|
|
8
|
+
"androidCxxLibName": "scrollguard"
|
|
9
|
+
},
|
|
10
|
+
"autolinking": {
|
|
11
|
+
"ScrollGuard": {
|
|
12
|
+
"swift": "HybridScrollGuard",
|
|
13
|
+
"kotlin": "HybridScrollGuard"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"ignorePaths": ["node_modules"]
|
|
17
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JHybridScrollGuardSpec.cpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#include "JHybridScrollGuardSpec.hpp"
|
|
9
|
+
|
|
10
|
+
// Forward declaration of `ScrollGuardDirection` to properly resolve imports.
|
|
11
|
+
namespace margelo::nitro::scrollguard { enum class ScrollGuardDirection; }
|
|
12
|
+
|
|
13
|
+
#include "ScrollGuardDirection.hpp"
|
|
14
|
+
#include <optional>
|
|
15
|
+
#include "JScrollGuardDirection.hpp"
|
|
16
|
+
|
|
17
|
+
namespace margelo::nitro::scrollguard {
|
|
18
|
+
|
|
19
|
+
jni::local_ref<JHybridScrollGuardSpec::jhybriddata> JHybridScrollGuardSpec::initHybrid(jni::alias_ref<jhybridobject> jThis) {
|
|
20
|
+
return makeCxxInstance(jThis);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
void JHybridScrollGuardSpec::registerNatives() {
|
|
24
|
+
registerHybrid({
|
|
25
|
+
makeNativeMethod("initHybrid", JHybridScrollGuardSpec::initHybrid),
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
size_t JHybridScrollGuardSpec::getExternalMemorySize() noexcept {
|
|
30
|
+
static const auto method = javaClassStatic()->getMethod<jlong()>("getMemorySize");
|
|
31
|
+
return method(_javaPart);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
void JHybridScrollGuardSpec::dispose() noexcept {
|
|
35
|
+
static const auto method = javaClassStatic()->getMethod<void()>("dispose");
|
|
36
|
+
method(_javaPart);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
std::string JHybridScrollGuardSpec::toString() {
|
|
40
|
+
static const auto method = javaClassStatic()->getMethod<jni::JString()>("toString");
|
|
41
|
+
auto javaString = method(_javaPart);
|
|
42
|
+
return javaString->toStdString();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Properties
|
|
46
|
+
std::optional<ScrollGuardDirection> JHybridScrollGuardSpec::getDirection() {
|
|
47
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JScrollGuardDirection>()>("getDirection");
|
|
48
|
+
auto __result = method(_javaPart);
|
|
49
|
+
return __result != nullptr ? std::make_optional(__result->toCpp()) : std::nullopt;
|
|
50
|
+
}
|
|
51
|
+
void JHybridScrollGuardSpec::setDirection(std::optional<ScrollGuardDirection> direction) {
|
|
52
|
+
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JScrollGuardDirection> /* direction */)>("setDirection");
|
|
53
|
+
method(_javaPart, direction.has_value() ? JScrollGuardDirection::fromCpp(direction.value()) : nullptr);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Methods
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
} // namespace margelo::nitro::scrollguard
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridScrollGuardSpec.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include <NitroModules/JHybridObject.hpp>
|
|
11
|
+
#include <fbjni/fbjni.h>
|
|
12
|
+
#include "HybridScrollGuardSpec.hpp"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
namespace margelo::nitro::scrollguard {
|
|
18
|
+
|
|
19
|
+
using namespace facebook;
|
|
20
|
+
|
|
21
|
+
class JHybridScrollGuardSpec: public jni::HybridClass<JHybridScrollGuardSpec, JHybridObject>,
|
|
22
|
+
public virtual HybridScrollGuardSpec {
|
|
23
|
+
public:
|
|
24
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/scrollguard/HybridScrollGuardSpec;";
|
|
25
|
+
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis);
|
|
26
|
+
static void registerNatives();
|
|
27
|
+
|
|
28
|
+
protected:
|
|
29
|
+
// C++ constructor (called from Java via `initHybrid()`)
|
|
30
|
+
explicit JHybridScrollGuardSpec(jni::alias_ref<jhybridobject> jThis) :
|
|
31
|
+
HybridObject(HybridScrollGuardSpec::TAG),
|
|
32
|
+
HybridBase(jThis),
|
|
33
|
+
_javaPart(jni::make_global(jThis)) {}
|
|
34
|
+
|
|
35
|
+
public:
|
|
36
|
+
~JHybridScrollGuardSpec() override {
|
|
37
|
+
// Hermes GC can destroy JS objects on a non-JNI Thread.
|
|
38
|
+
jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public:
|
|
42
|
+
size_t getExternalMemorySize() noexcept override;
|
|
43
|
+
void dispose() noexcept override;
|
|
44
|
+
std::string toString() override;
|
|
45
|
+
|
|
46
|
+
public:
|
|
47
|
+
inline const jni::global_ref<JHybridScrollGuardSpec::javaobject>& getJavaPart() const noexcept {
|
|
48
|
+
return _javaPart;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
// Properties
|
|
53
|
+
std::optional<ScrollGuardDirection> getDirection() override;
|
|
54
|
+
void setDirection(std::optional<ScrollGuardDirection> direction) override;
|
|
55
|
+
|
|
56
|
+
public:
|
|
57
|
+
// Methods
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
private:
|
|
61
|
+
friend HybridBase;
|
|
62
|
+
using HybridBase::HybridBase;
|
|
63
|
+
jni::global_ref<JHybridScrollGuardSpec::javaobject> _javaPart;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
} // namespace margelo::nitro::scrollguard
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JScrollGuardDirection.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include <fbjni/fbjni.h>
|
|
11
|
+
#include "ScrollGuardDirection.hpp"
|
|
12
|
+
|
|
13
|
+
namespace margelo::nitro::scrollguard {
|
|
14
|
+
|
|
15
|
+
using namespace facebook;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The C++ JNI bridge between the C++ enum "ScrollGuardDirection" and the the Kotlin enum "ScrollGuardDirection".
|
|
19
|
+
*/
|
|
20
|
+
struct JScrollGuardDirection final: public jni::JavaClass<JScrollGuardDirection> {
|
|
21
|
+
public:
|
|
22
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/scrollguard/ScrollGuardDirection;";
|
|
23
|
+
|
|
24
|
+
public:
|
|
25
|
+
/**
|
|
26
|
+
* Convert this Java/Kotlin-based enum to the C++ enum ScrollGuardDirection.
|
|
27
|
+
*/
|
|
28
|
+
[[maybe_unused]]
|
|
29
|
+
[[nodiscard]]
|
|
30
|
+
ScrollGuardDirection toCpp() const {
|
|
31
|
+
static const auto clazz = javaClassStatic();
|
|
32
|
+
static const auto fieldOrdinal = clazz->getField<int>("value");
|
|
33
|
+
int ordinal = this->getFieldValue(fieldOrdinal);
|
|
34
|
+
return static_cast<ScrollGuardDirection>(ordinal);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public:
|
|
38
|
+
/**
|
|
39
|
+
* Create a Java/Kotlin-based enum with the given C++ enum's value.
|
|
40
|
+
*/
|
|
41
|
+
[[maybe_unused]]
|
|
42
|
+
static jni::alias_ref<JScrollGuardDirection> fromCpp(ScrollGuardDirection value) {
|
|
43
|
+
static const auto clazz = javaClassStatic();
|
|
44
|
+
static const auto fieldHORIZONTAL = clazz->getStaticField<JScrollGuardDirection>("HORIZONTAL");
|
|
45
|
+
static const auto fieldVERTICAL = clazz->getStaticField<JScrollGuardDirection>("VERTICAL");
|
|
46
|
+
static const auto fieldBOTH = clazz->getStaticField<JScrollGuardDirection>("BOTH");
|
|
47
|
+
|
|
48
|
+
switch (value) {
|
|
49
|
+
case ScrollGuardDirection::HORIZONTAL:
|
|
50
|
+
return clazz->getStaticFieldValue(fieldHORIZONTAL);
|
|
51
|
+
case ScrollGuardDirection::VERTICAL:
|
|
52
|
+
return clazz->getStaticFieldValue(fieldVERTICAL);
|
|
53
|
+
case ScrollGuardDirection::BOTH:
|
|
54
|
+
return clazz->getStaticFieldValue(fieldBOTH);
|
|
55
|
+
default:
|
|
56
|
+
std::string stringValue = std::to_string(static_cast<int>(value));
|
|
57
|
+
throw std::invalid_argument("Invalid enum value (" + stringValue + "!");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
} // namespace margelo::nitro::scrollguard
|