Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions apps/example/__tests__/nitro.views.harness.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ function expectRed(actualCoverage: PixelCoverage): void {

const INITIAL_SIZE = { width: 80, height: 60 }
const RESIZED_SIZE = { width: 160, height: 120 }
const INITIAL_INT64_VALUE = 9_007_199_254_740_993n
const UPDATED_INT64_VALUE = -9_007_199_254_740_993n
const RENDER_TIMEOUT = 4_000
const SUPPORTS_NATIVE_VIEW_RECYCLING =
Platform.OS === 'ios' || Number(Platform.Version) >= 28
Expand Down Expand Up @@ -195,6 +197,7 @@ describe('TestView', () => {
hybridRef={callback((view) => viewRef.resolve(view))}
isBlue={true}
hasBeenCalled={false}
int64Value={INITIAL_INT64_VALUE}
colorScheme="dark"
someCallback={callback(onSomeCallback)}
onLayout={({ nativeEvent }) => layout.resolve(nativeEvent.layout)}
Expand All @@ -208,6 +211,7 @@ describe('TestView', () => {
expect(reportedLayout.height).toBeCloseTo(INITIAL_SIZE.height, 0)
expect(mountedView.isBlue).toBe(true)
expect(mountedView.hasBeenCalled).toBe(false)
expect(mountedView.int64Value).toBe(INITIAL_INT64_VALUE)
expect(mountedView.colorScheme).toBe('dark')
expect(mountedView.getOnDropViewCount()).toBe(0)
expect(HybridTestObjectCpp.getIsViewBlue(mountedView)).toBe(true)
Expand All @@ -234,13 +238,15 @@ describe('TestView', () => {
hybridRef={callback((view) => initialRef.resolve(view))}
isBlue={true}
hasBeenCalled={false}
int64Value={INITIAL_INT64_VALUE}
colorScheme="dark"
someCallback={callback(initialCallback)}
/>,
{ timeout: RENDER_TIMEOUT }
)

const firstView = await initialRef.promise
expect(firstView.int64Value).toBe(INITIAL_INT64_VALUE)
const blueCapture = await captureView('test-view-updates')
expectRenderedSize(blueCapture.size, INITIAL_SIZE)
expectBlue(blueCapture.pixelCoverage)
Expand All @@ -260,6 +266,7 @@ describe('TestView', () => {
hybridRef={updatedHybridRef}
isBlue={false}
hasBeenCalled={true}
int64Value={UPDATED_INT64_VALUE}
colorScheme="light"
someCallback={updatedSomeCallback}
/>
Expand All @@ -269,6 +276,7 @@ describe('TestView', () => {
expect(updatedView.equals(firstView)).toBe(true)
expect(updatedView.isBlue).toBe(false)
expect(updatedView.hasBeenCalled).toBe(true)
expect(updatedView.int64Value).toBe(UPDATED_INT64_VALUE)
expect(updatedView.colorScheme).toBe('light')
expect(updatedView.getOnDropViewCount()).toBe(0)
expect(HybridTestObjectCpp.getIsViewBlue(updatedView)).toBe(false)
Expand All @@ -291,6 +299,7 @@ describe('TestView', () => {
hybridRef={updatedHybridRef}
isBlue={false}
hasBeenCalled={true}
int64Value={UPDATED_INT64_VALUE}
colorScheme="light"
someCallback={updatedSomeCallback}
onLayout={({ nativeEvent }) =>
Expand All @@ -304,6 +313,7 @@ describe('TestView', () => {
expect(reportedResizedLayout.height).toBeCloseTo(RESIZED_SIZE.height, 0)
expect(firstView.isBlue).toBe(false)
expect(firstView.hasBeenCalled).toBe(true)
expect(firstView.int64Value).toBe(UPDATED_INT64_VALUE)
expect(firstView.colorScheme).toBe('light')

const resizedCapture = await captureView('test-view-updates')
Expand All @@ -324,6 +334,7 @@ describe('TestView', () => {
hybridRef={stableHybridRef}
isBlue={false}
hasBeenCalled={false}
int64Value={0n}
colorScheme="dark"
someCallback={stableSomeCallback}
/>,
Expand All @@ -346,6 +357,7 @@ describe('TestView', () => {
)}
isBlue={true}
hasBeenCalled={false}
int64Value={0n}
colorScheme="dark"
someCallback={stableSomeCallback}
/>
Expand All @@ -371,6 +383,7 @@ describe('TestView', () => {
hybridRef={stableHybridRef}
isBlue={false}
hasBeenCalled={false}
int64Value={0n}
colorScheme="dark"
someCallback={stableSomeCallback}
nativeDefaultValue={1}
Expand All @@ -392,6 +405,7 @@ describe('TestView', () => {
)}
isBlue={false}
hasBeenCalled={false}
int64Value={0n}
colorScheme="dark"
someCallback={stableSomeCallback}
nativeDefaultValue={2}
Expand All @@ -416,6 +430,7 @@ describe('TestView', () => {
hybridRef={isBlueUpdatedHybridRef}
isBlue={true}
hasBeenCalled={false}
int64Value={0n}
colorScheme="dark"
someCallback={stableSomeCallback}
nativeDefaultValue={2}
Expand All @@ -436,6 +451,7 @@ describe('TestView', () => {
hybridRef={isBlueUpdatedHybridRef}
isBlue={true}
hasBeenCalled={false}
int64Value={0n}
colorScheme="dark"
someCallback={stableSomeCallback}
nativeDefaultValue={2}
Expand All @@ -461,6 +477,7 @@ describe('TestView', () => {
hybridRef={callback((view) => firstRef.resolve(view))}
isBlue={true}
hasBeenCalled={false}
int64Value={0n}
colorScheme="dark"
someCallback={callback(fn())}
/>,
Expand Down Expand Up @@ -488,6 +505,7 @@ describe('TestView', () => {
hybridRef={callback((view) => secondRef.resolve(view))}
isBlue={false}
hasBeenCalled={true}
int64Value={0n}
colorScheme="light"
someCallback={callback(fn())}
/>,
Expand Down
1 change: 1 addition & 0 deletions apps/example/src/screens/ViewScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function ViewScreenImpl() {
someCallback={callback(() => console.log(`Callback called!`))}
colorScheme="dark"
hasBeenCalled={false}
int64Value={0n}
onTouchEnd={() => {
console.log(`Touched View #${i}!`)
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class HybridTestView(
view.setBackgroundColor(color)
}
override var hasBeenCalled: Boolean = false
override var int64Value: Long = 0L
override var colorScheme: ColorScheme = ColorScheme.LIGHT
override var someCallback: () -> Unit = {}
override var nativeDefaultValue: Double? = 42.0
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-nitro-test/ios/HybridTestView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class HybridTestView: HybridTestViewSpec {
}
}
var hasBeenCalled: Bool = false
var int64Value: Int64 = 0
var colorScheme: ColorScheme = .light
var someCallback: () -> Void = {}
var nativeDefaultValue: Double? = 42 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ namespace margelo::nitro::test {
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jboolean /* hasBeenCalled */)>("setHasBeenCalled");
method(_javaPart, hasBeenCalled);
}
int64_t JHybridTestViewSpec::getInt64Value() {
static const auto method = _javaPart->javaClassStatic()->getMethod<int64_t()>("getInt64Value");
auto __result = method(_javaPart);
return __result;
}
void JHybridTestViewSpec::setInt64Value(int64_t int64Value) {
static const auto method = _javaPart->javaClassStatic()->getMethod<void(int64_t /* int64Value */)>("setInt64Value");
method(_javaPart, int64Value);
}
ColorScheme JHybridTestViewSpec::getColorScheme() {
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JColorScheme>()>("getColorScheme");
auto __result = method(_javaPart);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ namespace margelo::nitro::test {
void setIsBlue(bool isBlue) override;
bool getHasBeenCalled() override;
void setHasBeenCalled(bool hasBeenCalled) override;
int64_t getInt64Value() override;
void setInt64Value(int64_t int64Value) override;
ColorScheme getColorScheme() override;
void setColorScheme(ColorScheme colorScheme) override;
std::function<void()> getSomeCallback() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ void JHybridTestViewStateUpdater::updateViewProps(jni::alias_ref<jni::JClass> /*
: !newProps->hasBeenCalled.hasSameValue(oldProps->hasBeenCalled)) {
hybridView->setHasBeenCalled(newProps->hasBeenCalled.get());
}
if (oldProps == nullptr
? newProps->int64Value.isProvided()
: !newProps->int64Value.hasSameValue(oldProps->int64Value)) {
hybridView->setInt64Value(newProps->int64Value.get());
}
if (oldProps == nullptr
? newProps->colorScheme.isProvided()
: !newProps->colorScheme.hasSameValue(oldProps->colorScheme)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ abstract class HybridTestViewSpec: HybridView() {
@set:Keep
abstract var hasBeenCalled: Boolean

@get:DoNotStrip
@get:Keep
@set:DoNotStrip
@set:Keep
abstract var int64Value: Long

@get:DoNotStrip
@get:Keep
@set:DoNotStrip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ namespace margelo::nitro::test {
inline void setHasBeenCalled(bool hasBeenCalled) noexcept override {
_swiftPart.setHasBeenCalled(std::forward<decltype(hasBeenCalled)>(hasBeenCalled));
}
inline int64_t getInt64Value() noexcept override {
return _swiftPart.getInt64Value();
}
inline void setInt64Value(int64_t int64Value) noexcept override {
_swiftPart.setInt64Value(std::forward<decltype(int64Value)>(int64Value));
}
inline ColorScheme getColorScheme() noexcept override {
auto __result = _swiftPart.getColorScheme();
return static_cast<ColorScheme>(__result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ - (void) updateProps:(const std::shared_ptr<const react::Props>&)props
: !newViewProps.hasBeenCalled.hasSameValue(oldViewProps->hasBeenCalled)) {
swiftPart.setHasBeenCalled(newViewProps.hasBeenCalled.get());
}
// int64Value: int64
if (oldViewProps == nullptr
? newViewProps.int64Value.isProvided()
: !newViewProps.int64Value.hasSameValue(oldViewProps->int64Value)) {
swiftPart.setInt64Value(newViewProps.int64Value.get());
}
// colorScheme: enum
if (oldViewProps == nullptr
? newViewProps.colorScheme.isProvided()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public protocol HybridTestViewSpec_protocol: HybridObject, HybridView {
// Properties
var isBlue: Bool { get set }
var hasBeenCalled: Bool { get set }
var int64Value: Int64 { get set }
var colorScheme: ColorScheme { get set }
var someCallback: () -> Void { get set }
var nativeDefaultValue: Double? { get set }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,17 @@ open class HybridTestViewSpec_cxx {
}
}

public final var int64Value: Int64 {
@inline(__always)
get {
return self.__implementation.int64Value
}
@inline(__always)
set {
self.__implementation.int64Value = newValue
}
}

public final var colorScheme: Int32 {
@inline(__always)
get {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace margelo::nitro::test {
prototype.registerHybridSetter("isBlue", &HybridTestViewSpec::setIsBlue);
prototype.registerHybridGetter("hasBeenCalled", &HybridTestViewSpec::getHasBeenCalled);
prototype.registerHybridSetter("hasBeenCalled", &HybridTestViewSpec::setHasBeenCalled);
prototype.registerHybridGetter("int64Value", &HybridTestViewSpec::getInt64Value);
prototype.registerHybridSetter("int64Value", &HybridTestViewSpec::setInt64Value);
prototype.registerHybridGetter("colorScheme", &HybridTestViewSpec::getColorScheme);
prototype.registerHybridSetter("colorScheme", &HybridTestViewSpec::setColorScheme);
prototype.registerHybridGetter("someCallback", &HybridTestViewSpec::getSomeCallback);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ namespace margelo::nitro::test {
virtual void setIsBlue(bool isBlue) = 0;
virtual bool getHasBeenCalled() = 0;
virtual void setHasBeenCalled(bool hasBeenCalled) = 0;
virtual int64_t getInt64Value() = 0;
virtual void setInt64Value(int64_t int64Value) = 0;
virtual ColorScheme getColorScheme() = 0;
virtual void setColorScheme(ColorScheme colorScheme) = 0;
virtual std::function<void()> getSomeCallback() = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace margelo::nitro::test::views {
react::ViewProps(context, sourceProps, rawProps, filterObjectKeys),
isBlue(nitro::ReactProp<bool>::fromRawValue("TestView", "isBlue", rawProps, sourceProps.isBlue)),
hasBeenCalled(nitro::ReactProp<bool>::fromRawValue("TestView", "hasBeenCalled", rawProps, sourceProps.hasBeenCalled)),
int64Value(nitro::ReactProp<int64_t>::fromRawValue("TestView", "int64Value", rawProps, sourceProps.int64Value)),
colorScheme(nitro::ReactProp<ColorScheme>::fromRawValue("TestView", "colorScheme", rawProps, sourceProps.colorScheme)),
someCallback(nitro::ReactProp<std::function<void()>>::fromRawValue("TestView", "someCallback", rawProps, sourceProps.someCallback)),
nativeDefaultValue(nitro::ReactProp<std::optional<double>>::fromRawValue("TestView", "nativeDefaultValue", rawProps, sourceProps.nativeDefaultValue)),
Expand All @@ -31,6 +32,7 @@ namespace margelo::nitro::test::views {
switch (hashString(propName)) {
case hashString("isBlue"): return true;
case hashString("hasBeenCalled"): return true;
case hashString("int64Value"): return true;
case hashString("colorScheme"): return true;
case hashString("someCallback"): return true;
case hashString("nativeDefaultValue"): return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace margelo::nitro::test::views {
public:
nitro::ReactProp<bool> isBlue;
nitro::ReactProp<bool> hasBeenCalled;
nitro::ReactProp<int64_t> int64Value;
nitro::ReactProp<ColorScheme> colorScheme;
nitro::ReactProp<std::function<void()>> someCallback;
nitro::ReactProp<std::optional<double>> nativeDefaultValue;
Expand All @@ -54,6 +55,7 @@ namespace margelo::nitro::test::views {
bool hasSameProps(const HybridTestViewProps& other) const noexcept {
return isBlue.hasSameValue(other.isBlue) &&
hasBeenCalled.hasSameValue(other.hasBeenCalled) &&
int64Value.hasSameValue(other.int64Value) &&
colorScheme.hasSameValue(other.colorScheme) &&
someCallback.hasSameValue(other.someCallback) &&
nativeDefaultValue.hasSameValue(other.nativeDefaultValue) &&
Expand All @@ -64,6 +66,7 @@ namespace margelo::nitro::test::views {
bool hasAnyProvidedProps() const noexcept {
return isBlue.isProvided() ||
hasBeenCalled.isProvided() ||
int64Value.isProvided() ||
colorScheme.isProvided() ||
someCallback.isProvided() ||
nativeDefaultValue.isProvided() ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"validAttributes": {
"isBlue": true,
"hasBeenCalled": true,
"int64Value": true,
"colorScheme": true,
"someCallback": true,
"nativeDefaultValue": true,
Expand Down
2 changes: 2 additions & 0 deletions packages/react-native-nitro-test/src/specs/TestView.nitro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import type {
HybridView as HybridViewAlias,
HybridViewMethods,
HybridViewProps,
Int64,
} from 'react-native-nitro-modules'

export type ColorScheme = 'light' | 'dark'

export interface TestViewProps extends HybridViewProps {
isBlue: boolean
hasBeenCalled: boolean
int64Value: Int64
colorScheme: ColorScheme
someCallback: () => void
nativeDefaultValue?: number
Expand Down
Loading