-
Notifications
You must be signed in to change notification settings - Fork 734
FeatureHighlight - migrate to new api, remove unsafe method #1290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1f2be57
05d0d32
f04e4b6
34aaae8
7d56142
214ae80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,11 +148,31 @@ class FeatureHighlight extends BaseComponent { | |
this.setTargetPosition(); | ||
} | ||
|
||
UNSAFE_componentWillReceiveProps(nextProps) { | ||
this.setTargetPosition(nextProps); | ||
static getDerivedStateFromProps(nextProps, prevState) { | ||
if (prevState?.getTarget === nextProps?.getTarget) { | ||
return null; | ||
} | ||
|
||
const target = nextProps?.getTarget?.(); | ||
const node = FeatureHighlight.findTargetNode(target); | ||
if (node && node !== prevState?.node) { | ||
return {getTarget: nextProps?.getTarget, node}; | ||
} | ||
return null; | ||
} | ||
|
||
componentDidUpdate() { | ||
shouldSetTargetPosition = (nextProps) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like 'shouldComponentUpdate'... If it's not a pure component you can just implement that method instead and the component will not be updated if it doesn't meet the condition. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've tried it before and now again, it's not quite working. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wierd. Ok... |
||
return ( | ||
nextProps.getTarget() !== this.props.getTarget() || | ||
nextProps.title !== this.props.title || | ||
nextProps.visible !== this.props.visible | ||
); | ||
} | ||
|
||
componentDidUpdate(nextProps) { | ||
if (this.shouldSetTargetPosition(nextProps)) { | ||
this.setTargetPosition(); | ||
} | ||
if (this.viewRef) { | ||
this.setAccessibilityFocus(this.viewRef); | ||
} | ||
|
@@ -163,7 +183,7 @@ class FeatureHighlight extends BaseComponent { | |
AccessibilityInfo.setAccessibilityFocus(reactTag); | ||
} | ||
|
||
findTargetNode(target) { | ||
static findTargetNode(target) { | ||
Inbal-Tish marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return findNodeHandle(target); | ||
} | ||
|
||
|
@@ -181,9 +201,6 @@ class FeatureHighlight extends BaseComponent { | |
setTargetPosition(props = this.props) { | ||
if (props.getTarget !== undefined) { | ||
const target = props.getTarget(); | ||
|
||
const node = this.findTargetNode(target); | ||
this.setState({node}); | ||
if (target) { | ||
setTimeout(() => { | ||
target.measureInWindow((x, y, width, height) => { | ||
|
Uh oh!
There was an error while loading. Please reload this page.