Skip to content

Commit

Permalink
[0.74] Cherry-pick a few fixes to 0.74 (#13232)
Browse files Browse the repository at this point in the history
* Cleanup the snapshots in E2E test app (#13229)

* Cleanup the snapshots

* format

* Process snapshots so that ImageSource Uri's are consistent

* Change files

* fix

* fix

* fix(TextInput/isFocused): correctly handle null focused input (#13219)

* Change files

* fix(TextInput/isFocused): correctly handle null focused input

Signed-off-by: Nathanael Bracy <nate@bracy.dev>

* fix

---------

Signed-off-by: Nathanael Bracy <nate@bracy.dev>
Co-authored-by: Andrew Coates <30809111+acoates-ms@users.noreply.github.com>

* Fixing crash when passing null children to view with no-hide-descendents (#13224)

* Preventing crash when passing null children to view with no-hide-descendents

* Change files

---------

Co-authored-by: Sam Walker <sawalker@microsoft.com>
Co-authored-by: Andrew <30809111+acoates-ms@users.noreply.github.com>

* C++20: use view() instead of str() to avoid a copy, use starts_with (#13218)

* Change files

* C++20: use view() instead of str() to avoid a copy, use starts_with

Signed-off-by: Nathanael Bracy <nate@bracy.dev>

* fix

* Apply changefile modifications from code review

Co-authored-by: Jon Thysell <thysell@gmail.com>

* Revert package.json

Signed-off-by: Nathanael Bracy <nate@bracy.dev>

---------

Signed-off-by: Nathanael Bracy <nate@bracy.dev>
Co-authored-by: Andrew Coates <30809111+acoates-ms@users.noreply.github.com>
Co-authored-by: Jon Thysell <thysell@gmail.com>

* ViewComponentView should be activatable from rn-win32.dll (#13225)

* ViewComponentView should be activatable from rn-win32.dll

* Change files

* Cleanup the snapshots in E2E test app (#13229)

* Cleanup the snapshots

* format

* Process snapshots so that ImageSource Uri's are consistent

* Change files

* fix

* fix

* lint

* format

* Revert "C++20: use view() instead of str() to avoid a copy, use starts_with (#13218)"

This reverts commit 71335b5.

---------

Signed-off-by: Nathanael Bracy <nate@bracy.dev>
Co-authored-by: Nate <37554478+servusdei2018@users.noreply.github.com>
Co-authored-by: Sam Walker <samuel.ls.walker@gmail.com>
Co-authored-by: Sam Walker <sawalker@microsoft.com>
Co-authored-by: Jon Thysell <thysell@gmail.com>
  • Loading branch information
5 people committed May 14, 2024
1 parent ef17989 commit 481f89d
Show file tree
Hide file tree
Showing 60 changed files with 13,999 additions and 33,462 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix(TextInput/isFocused): correctly handle null focused input",
"packageName": "@office-iss/react-native-win32",
"email": "nate@bracy.dev",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Process snapshots so that ImageSource Uri's are consistent",
"packageName": "@react-native-windows/automation-commands",
"email": "30809111+acoates-ms@users.noreply.github.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Preventing crash when passing null children to view with no-hide-descendents",
"packageName": "react-native-windows",
"email": "30809111+acoates-ms@users.noreply.github.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Expose ImageProps from ImageComponentView's and add ImageSource type",
"packageName": "react-native-windows",
"email": "30809111+acoates-ms@users.noreply.github.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "ViewComponentView should be activatable from rn-win32.dll",
"packageName": "react-native-windows",
"email": "30809111+acoates-ms@users.noreply.github.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix(TextInput/isFocused): correctly handle null focused input",
"packageName": "react-native-windows",
"email": "nate@bracy.dev",
"dependentChangeType": "none"
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,6 @@
},
"resolutions.justification": {
"z-schema": "CVE-2021-3765 in validator. z-schema is used by rush which is a dependency of lage so should not be executed in this repo"
}
}
},
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
Original file line number Diff line number Diff line change
Expand Up @@ -1314,9 +1314,13 @@ function InternalTextInput(props: Props): React.Node {
);
}
},
// TODO: Fix this returning true on null === null, when no input is focused
isFocused(): boolean {
return TextInputState.currentlyFocusedInput() === inputRef.current;
const currentlyFocusedInput =
TextInputState.currentlyFocusedInput();
return (
currentlyFocusedInput !== null &&
currentlyFocusedInput === inputRef.current
);
},
getNativeRef(): ?React.ElementRef<HostComponent<mixed>> {
return inputRef.current;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,36 @@ export type UIElement = {
[index: string]: unknown;
};

export type AutomationNode = {
AutomationId?: string;
ControlType?: number;
LocalizedControlType?: string;
__Children?: [AutomationNode];
};

export type ComponentNode = {
Type: string;
_Props?: {
TestId?: string;
Sources?: [{Uri?: string}];
};
__Children?: [ComponentNode];
};

export type VisualNode = {
Comment?: string;
Offset?: `${number} ${number} ${number}`;
Size?: `${number} ${number}`;
'Visual Type'?: string;
__Children?: [VisualNode];
};

export type VisualTree = {
'Automation Tree': AutomationNode;
'Component Tree': ComponentNode;
'Visual Tree': VisualNode;
};

declare global {
const automationClient: AutomationClient | undefined;
}
Expand All @@ -46,9 +76,10 @@ export default async function dumpVisualTree(
pruneCollapsed?: boolean;
deterministicOnly?: boolean;
removeDefaultProps?: boolean;
removeGuidsFromImageSources?: boolean;
additionalProperties?: string[];
},
): Promise<UIElement> {
): Promise<UIElement | VisualTree> {
if (!automationClient) {
throw new Error('RPC client is not enabled');
}
Expand All @@ -62,23 +93,87 @@ export default async function dumpVisualTree(
throw new Error(dumpResponse.message);
}

const element = dumpResponse.result;
const element: UIElement | VisualTree = dumpResponse.result;

if (opts?.pruneCollapsed !== false) {
if ('XamlType' in element && opts?.pruneCollapsed !== false) {
pruneCollapsedElements(element);
}

if (opts?.deterministicOnly !== false) {
if ('XamlType' in element && opts?.deterministicOnly !== false) {
removeNonDeterministicProps(element);
}

if (opts?.removeDefaultProps !== false) {
if ('XamlType' in element && opts?.removeDefaultProps !== false) {
removeDefaultProps(element);
}

if (!('XamlType' in element) && opts?.removeGuidsFromImageSources !== false) {
removeGuidsFromImageSources(element);
}

return element;
}

function removeGuidsFromImageSourcesHelper(node: ComponentNode) {
if (node._Props && node._Props.Sources) {
node._Props.Sources.forEach((source: any) => {
if (source.Uri) {
if (source.Uri.startsWith('blob:')) {
source.Uri = source.Uri.replace(
/blob:[a-f0-9]+-[a-f0-9]+-[a-f0-9]+-[a-f0-9]+-[a-f0-9]+/,
'blob:<some_guid_here>',
);
} else if (
source.Uri.startsWith('https://www.facebook.com/favicon.ico?r=1&t=')
) {
source.Uri =
'https://www.facebook.com/favicon.ico?r=1&t=<some_hash_here>';
} else if (
source.Uri.startsWith(
'https://www.facebook.com/ads/pics/successstories.png?hash=',
)
) {
source.Uri =
'https://www.facebook.com/ads/pics/successstories.png?hash=<some_hash_here>';
} else {
// When getting files from a prebuilt bundle the uri is going to include a local path, which would make snapshots inconsistent,
// This logic replaces the local path so that we get consistent results.
// file://E:\\repos\\react-native-windows\\packages\\e2e-test-app-fabric\\windows\\RNTesterApp-Fabric.Package\\bin\\x64\\Release\\AppX\\RNTesterApp-Fabric\\Bundle\\@react-native-windows/tester/js/assets/uie_thumb_normal@2x.png
// becomes
// <localOrBundlerUri>@react-native-windows/tester/js/assets/uie_thumb_normal@2x.png
const packagesPath = require('path')
.resolve(__dirname, '../../..')
.replace(/\\/g, '\\\\');
source.Uri = source.Uri.replace(
new RegExp(`file://${packagesPath}.*\\\\Bundle\\\\assets/_+`),
'<localOrBundlerUri>',
);

// When loading the bundle from metro local paths will be replaced with paths to localhost, which will not align with snapshots made with prebuilt bundles.
// This logic replaces the localhost uri, with the same uri that we would have gotten from a prebuild bundle. This makes it easier to debug without breaking snapshots
// http://localhost:8081/assets/@@/@react-native-windows/tester/js/assets/uie_thumb_normal@2x.png?platform=windows&hash=c6f5aec4d9e0aa47c0887e4266796224
// becomes
// "<localOrBundlerUri>@react-native-windows/tester/js/assets/uie_thumb_normal@2x.png"
source.Uri = source.Uri.replace(
/http:\/\/localhost:8081\/assets\/(@@\/)+/,
'<localOrBundlerUri>',
);
source.Uri = source.Uri.replace(/\?platform=windows&hash=[^=]$/, '');
}
}
});
}
if (node.__Children) {
node.__Children.forEach((child: any) =>
removeGuidsFromImageSourcesHelper(child),
);
}
}

function removeGuidsFromImageSources(visualTree: VisualTree) {
removeGuidsFromImageSourcesHelper(visualTree['Component Tree']);
}

/**
* Removes trees of XAML that are not visible.
*/
Expand Down
Loading

0 comments on commit 481f89d

Please sign in to comment.