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
3 changes: 3 additions & 0 deletions packages/rn-tester/.maestro/new-arch-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ appId: ${APP_ID} # iOS: com.meta.RNTester.localDevelopment | Android: com.facebo
- tapOn: 'Change Background'
- assertVisible:
text: 'HSBA: h: 0, s: 1, b: 1, a: 255'
- tapOn: 'Set Color Prop'
- assertVisible:
text: 'HSBA: h: 0, s: 0, b: 1, a: 255'
- assertVisible:
text: '> Interop Layer Measurements <'
- assertVisible:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @format
*/

import type {HostComponent, ViewProps} from 'react-native';
import type {ColorValue, HostComponent, ViewProps} from 'react-native';

import * as React from 'react';
import {UIManager, findNodeHandle, requireNativeComponent} from 'react-native';
Expand All @@ -27,7 +27,7 @@ type ColorChangedEvent = {
type NativeProps = Readonly<{
...ViewProps,
opacity?: number,
color?: string,
color?: ColorValue,
onColorChanged?: (event: ColorChangedEvent) => void,
}>;

Expand Down
22 changes: 22 additions & 0 deletions packages/rn-tester/NativeComponentExample/js/MyNativeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import type {MyLegacyViewType} from './MyLegacyViewNativeComponent';
import type {MyNativeViewType} from './MyNativeViewNativeComponent';
import type {ColorValue} from 'react-native';

import RNTMyLegacyNativeView from './MyLegacyViewNativeComponent';
import {
Expand All @@ -33,6 +34,12 @@ const colors = [
'#000033',
];

const legacyColors: ReadonlyArray<ColorValue> = [
'rgb(255, 255, 255)',
'hsl(240, 100%, 50%)',
'steelblue',
];

const cornerRadiuses = [0, 20, 40, 60, 80, 100, 120];

class HSBA {
Expand Down Expand Up @@ -101,6 +108,7 @@ export default function MyNativeView(props: {}): React.Node {
const ref = useRef<React.ElementRef<MyNativeViewType> | null>(null);
const legacyRef = useRef<React.ElementRef<MyLegacyViewType> | null>(null);
const [currentBGColor, setCurrentBGColor] = useState<number>(0);
const [legacyColorIndex, setLegacyColorIndex] = useState<?number>(null);
const [opacity, setOpacity] = useState(1.0);
const [arrayValues, setArrayValues] = useState([1, 2, 3]);
const [hsba, setHsba] = useState<HSBA>(new HSBA());
Expand Down Expand Up @@ -141,6 +149,9 @@ export default function MyNativeView(props: {}): React.Node {
ref={legacyRef}
style={{flex: 1}}
opacity={opacity}
color={
legacyColorIndex == null ? undefined : legacyColors[legacyColorIndex]
}
onColorChanged={event => {
const normalizedHue =
Platform.OS === 'android'
Expand Down Expand Up @@ -195,6 +206,17 @@ export default function MyNativeView(props: {}): React.Node {
setCurrentBGColor(nextBGColor);
}}
/>
<Button
title="Set Color Prop"
onPress={() => {
setLegacyColorIndex(
legacyColorIndex == null ||
legacyColorIndex + 1 >= legacyColors.length
? 0
: legacyColorIndex + 1,
);
}}
/>
<Button
title="Set Opacity"
onPress={() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,9 @@ internal class MyLegacyViewManager(reactContext: ReactApplicationContext) :
super.setOpacity(view, opacity)
}

@ReactProp(name = ViewProps.COLOR)
fun setColor(view: MyNativeView, color: String?): Unit =
when (color) {
null -> view.setBackgroundColor(Color.TRANSPARENT)
else -> view.setBackgroundColor(Color.parseColor(color))
}
@ReactProp(name = ViewProps.COLOR, customType = "Color")
fun setColor(view: MyNativeView, color: Int?): Unit =
view.setBackgroundColor(color ?: Color.TRANSPARENT)

@ReactProp(name = "cornerRadius")
fun setCornerRadius(view: MyNativeView, cornerRadius: Float) {
Expand Down
Loading