Skip to content

Commit

Permalink
[0.72] Fix ref's on ViewWin32 (enables ViewWin32.focus() calls to wor…
Browse files Browse the repository at this point in the history
…k again) (#11543)

* Fix ref's on ViewWin32 (enables ViewWin32.focus() calls to work again)

* Change files
  • Loading branch information
acoates-ms committed May 1, 2023
1 parent 52f0652 commit 21a4e87
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Fix ref's on ViewWin32 (enables ViewWin32.focus() calls to work again)",
"packageName": "@office-iss/react-native-win32",
"email": "30809111+acoates-ms@users.noreply.github.com",
"dependentChangeType": "patch"
}
8 changes: 4 additions & 4 deletions packages/@office-iss/react-native-win32/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"flow-check": "flow check",
"lint:fix": "rnw-scripts lint:fix",
"lint": "rnw-scripts lint",
"run-win32-dev-web": "npx @office-iss/rex-win32@0.68.26-devmain.16206.10000 --bundle js/RNTesterApp --component RNTesterApp --basePath ./dist/win32/dev --jsEngine v8 --useDevMain --useWebDebugger",
"run-win32-devmain": "npx @office-iss/rex-win32@0.68.26-devmain.16206.10000 --bundle js/RNTesterApp --component RNTesterApp --basePath ./dist/win32/dev --jsEngine v8 --useDevMain",
"run-win32": "npx @office-iss/rex-win32@0.68.26-devmain.16206.10000 --bundle js/RNTesterApp --component RNTesterApp --basePath ./dist/win32/dev --jsEngine v8 --useWebDebugger",
"run-win32-dev-web": "npx @office-iss/rex-win32@0.68.33-devmain.16427.10000 --bundle js/RNTesterApp --component RNTesterApp --basePath ./dist/win32/dev --jsEngine v8 --useDevMain --useWebDebugger",
"run-win32-devmain": "npx @office-iss/rex-win32@0.68.33-devmain.16427.10000 --bundle js/RNTesterApp --component RNTesterApp --basePath ./dist/win32/dev --jsEngine v8 --useDevMain",
"run-win32": "npx @office-iss/rex-win32@0.68.33-devmain.16427.10000 --bundle js/RNTesterApp --component RNTesterApp --basePath ./dist/win32/dev --jsEngine v8 --useWebDebugger",
"start": "react-native start --projectRoot ../react-native-win32-tester",
"test": "jest",
"validate-overrides": "react-native-platform-override validate"
Expand Down Expand Up @@ -103,4 +103,4 @@
"engines": {
"node": ">= 14"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
*/

import * as React from 'react';
import {useCallback, useRef, useLayoutEffect} from 'react';
import {useLayoutEffect} from 'react';
import type {ViewProps} from './ViewPropTypes';

import View from './View';
import {findNodeHandle} from '../../ReactNative/RendererProxy';
import UIManager from '../../ReactNative/UIManager';
import useMergeRefs from '../../Utilities/useMergeRefs';
import warnOnce from '../../Utilities/warnOnce';

/**
Expand Down Expand Up @@ -100,40 +98,9 @@ const ViewWin32: React.AbstractComponent<
}
}, [accessibilityControls]);

/**
* Set up the forwarding ref to enable adding the focus method.
*/
const focusRef = useRef<typeof View | null>(null);

const setLocalRef = useCallback(
(instance: typeof View | null) => {
focusRef.current = instance;
/**
* Add focus() as a callable function to the forwarded reference.
*/
if (instance) {
// $FlowFixMe[prop-missing] - TODO - focus on a component should already call into TextInputState.focus.. once we remove the refs required for legacy accessibility*By ref support
instance.focus = () => {
UIManager.dispatchViewManagerCommand(
findNodeHandle(instance),
UIManager.getViewManagerConfig('RCTView').Commands.focus,
null,
);
};
}
},
[focusRef],
);

// $FlowFixMe
const setNativeRef = useMergeRefs<typeof View | null>({
setLocalRef,
forwardedRef,
});

return (
<View
ref={setNativeRef}
ref={forwardedRef}
{...rest}
{...(controlsTarget !== null
? {accessibilityControls: controlsTarget}
Expand Down

0 comments on commit 21a4e87

Please sign in to comment.