-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21227 from bernhardoj/fix/20847-scroll-manager
Fix crash when edit a message after coming back from a child report
- Loading branch information
Showing
14 changed files
with
254 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import {useContext} from 'react'; | ||
import ReportScreenContext from '../../pages/home/ReportScreenContext'; | ||
|
||
function useReportScrollManager() { | ||
const {flatListRef} = useContext(ReportScreenContext); | ||
|
||
/** | ||
* Scroll to the provided index. On non-native implementations we do not want to scroll when we are scrolling because | ||
* we are editing a comment. | ||
* | ||
* @param {Object} index | ||
* @param {Boolean} isEditing | ||
*/ | ||
const scrollToIndex = (index, isEditing) => { | ||
if (!flatListRef.current || isEditing) { | ||
return; | ||
} | ||
|
||
flatListRef.current.scrollToIndex(index); | ||
}; | ||
|
||
/** | ||
* Scroll to the bottom of the flatlist. | ||
*/ | ||
const scrollToBottom = () => { | ||
if (!flatListRef.current) { | ||
return; | ||
} | ||
|
||
flatListRef.current.scrollToOffset({animated: false, offset: 0}); | ||
}; | ||
|
||
return {ref: flatListRef, scrollToIndex, scrollToBottom}; | ||
} | ||
|
||
export default useReportScrollManager; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {useContext} from 'react'; | ||
import ReportScreenContext from '../../pages/home/ReportScreenContext'; | ||
|
||
function useReportScrollManager() { | ||
const {flatListRef} = useContext(ReportScreenContext); | ||
|
||
/** | ||
* Scroll to the provided index. | ||
* | ||
* @param {Object} index | ||
*/ | ||
const scrollToIndex = (index) => { | ||
if (!flatListRef.current) { | ||
return; | ||
} | ||
|
||
flatListRef.current.scrollToIndex(index); | ||
}; | ||
|
||
/** | ||
* Scroll to the bottom of the flatlist. | ||
*/ | ||
const scrollToBottom = () => { | ||
if (!flatListRef.current) { | ||
return; | ||
} | ||
|
||
flatListRef.current.scrollToOffset({animated: false, offset: 0}); | ||
}; | ||
|
||
return {ref: flatListRef, scrollToIndex, scrollToBottom}; | ||
} | ||
|
||
export default useReportScrollManager; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,30 @@ | ||
import React from 'react'; | ||
|
||
// This ref is created using React.createRef here because this function is used by a component that doesn't have access | ||
// to the original ref. | ||
const flatListRef = React.createRef(); | ||
|
||
/** | ||
* Scroll to the provided index. On non-native implementations we do not want to scroll when we are scrolling because | ||
* we are editing a comment. | ||
* | ||
* @param {Object} ref | ||
* @param {Object} index | ||
* @param {Boolean} isEditing | ||
*/ | ||
function scrollToIndex(index, isEditing) { | ||
if (isEditing) { | ||
function scrollToIndex(ref, index, isEditing) { | ||
if (!ref.current || isEditing) { | ||
return; | ||
} | ||
|
||
flatListRef.current.scrollToIndex(index); | ||
ref.current.scrollToIndex(index); | ||
} | ||
|
||
/** | ||
* Scroll to the bottom of the flatlist. | ||
* | ||
* @param {Object} ref | ||
*/ | ||
function scrollToBottom() { | ||
if (!flatListRef.current) { | ||
function scrollToBottom(ref) { | ||
if (!ref.current) { | ||
return; | ||
} | ||
|
||
flatListRef.current.scrollToOffset({animated: false, offset: 0}); | ||
ref.current.scrollToOffset({animated: false, offset: 0}); | ||
} | ||
|
||
export {flatListRef, scrollToIndex, scrollToBottom}; | ||
export {scrollToIndex, scrollToBottom}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
import React from 'react'; | ||
|
||
// This ref is created using React.createRef here because this function is used by a component that doesn't have access | ||
// to the original ref. | ||
const flatListRef = React.createRef(); | ||
|
||
/** | ||
* Scroll to the provided index. | ||
* | ||
* @param {Object} ref | ||
* @param {Object} index | ||
*/ | ||
function scrollToIndex(index) { | ||
flatListRef.current.scrollToIndex(index); | ||
function scrollToIndex(ref, index) { | ||
if (!ref.current) { | ||
return; | ||
} | ||
|
||
ref.current.scrollToIndex(index); | ||
} | ||
|
||
/** | ||
* Scroll to the bottom of the flatlist. | ||
* | ||
* @param {Object} ref | ||
*/ | ||
function scrollToBottom() { | ||
if (!flatListRef.current) { | ||
function scrollToBottom(ref) { | ||
if (!ref.current) { | ||
return; | ||
} | ||
|
||
flatListRef.current.scrollToOffset({animated: false, offset: 0}); | ||
ref.current.scrollToOffset({animated: false, offset: 0}); | ||
} | ||
|
||
export {flatListRef, scrollToIndex, scrollToBottom}; | ||
export {scrollToIndex, scrollToBottom}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.