Skip to content

Commit

Permalink
Fix html.img event bug in Fabric (#72)
Browse files Browse the repository at this point in the history
React Native's "Fabric" architecture appears to have a bug and does not
populate the Image 'load' event with 'source' data.
  • Loading branch information
necolas authored Apr 4, 2024
1 parent 429e2fe commit a770fc3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ export function createStrictDOMComponent<T: any, P: StrictProps>(
const { source } = e.nativeEvent;
onLoad({
target: {
naturalHeight: source.height,
naturalWidth: source.width
naturalHeight: source?.height,
naturalWidth: source?.width
},
type: 'load'
});
Expand Down
38 changes: 38 additions & 0 deletions packages/react-strict-dom/tests/html-test.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,44 @@ describe('html', () => {
expect(root.toJSON()).toMatchSnapshot();
});

test('"img" prop "onLoad"', () => {
const onLoad = jest.fn();

const root = create(<html.img onLoad={onLoad} src="https://src.jpg" />);
const element = root.toJSON();

// Expected event shape
element.props.onLoad({
nativeEvent: {
source: {
height: 100,
width: 200
}
}
});
expect(onLoad).toHaveBeenCalledWith({
target: {
naturalHeight: 100,
naturalWidth: 200
},
type: 'load'
});

// Fabric event bug
element.props.onLoad({
nativeEvent: {
source: undefined
}
});
expect(onLoad).toHaveBeenCalledWith({
target: {
naturalHeight: undefined,
naturalWidth: undefined
},
type: 'load'
});
});

test('"input" prop "autoComplete" value', () => {
[
'additional-name',
Expand Down

0 comments on commit a770fc3

Please sign in to comment.