From e6e1b93fc56ed37455b3df2e1acced6a11704e2c Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Wed, 15 Jan 2020 20:20:53 +0500 Subject: [PATCH] remove unecessary state updating --- .../src/components/ActionSheet/index.js | 32 +++++++++---------- .../components/ActionSheetComponent/index.js | 32 +++++++++---------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/apps/mobile/src/components/ActionSheet/index.js b/apps/mobile/src/components/ActionSheet/index.js index e3ad977ed..44a92330e 100644 --- a/apps/mobile/src/components/ActionSheet/index.js +++ b/apps/mobile/src/components/ActionSheet/index.js @@ -36,6 +36,7 @@ export default class ActionSheet extends Component { this.scrollAnimationEndValue; this.hasBounced; this.scrollViewRef; + this.layoutHasCalled = false; } _setModalVisible = () => { @@ -55,26 +56,25 @@ export default class ActionSheet extends Component { this.setState( { modalVisible: false, - layoutHasCalled: false, }, () => { + this.layoutHasCalled = false; if (typeof this.props.onClose === 'function') this.props.onClose(); }, ); - }, 150); + }, 500); }; _showModal = event => { let {gestureEnabled, bounceOffset, initialOffsetFromBottom} = this.props; let addFactor = deviceHeight * 0.1; let height = event.nativeEvent.layout.height; - console.log('layout called again'); - if (this.state.layoutHasCalled) { + if (this.layoutHasCalled) { let diff; if (height > this.customComponentHeight) { diff = height - this.customComponentHeight; this._scrollTo(this.prevScroll + diff); - console.log(this.prevScroll); + this.customComponentHeight = height; } else { diff = this.customComponentHeight - height; @@ -85,22 +85,22 @@ export default class ActionSheet extends Component { } else { this.customComponentHeight = height; - this._scrollTo( - gestureEnabled - ? this.customComponentHeight * initialOffsetFromBottom + - addFactor + - bounceOffset - : this.customComponentHeight + bounceOffset, - ); - this.setState({ - layoutHasCalled: true, - }); + setTimeout(() => { + this._scrollTo( + gestureEnabled + ? this.customComponentHeight * initialOffsetFromBottom + + addFactor + + bounceOffset + : this.customComponentHeight + bounceOffset, + ); + }, 300); + + this.layoutHasCalled = true; } }; _onScrollBeginDrag = event => { let verticalOffset = event.nativeEvent.contentOffset.y; - this.prevScroll = verticalOffset; }; diff --git a/apps/mobile/src/components/ActionSheetComponent/index.js b/apps/mobile/src/components/ActionSheetComponent/index.js index 72f927d22..2e2fa6ccf 100644 --- a/apps/mobile/src/components/ActionSheetComponent/index.js +++ b/apps/mobile/src/components/ActionSheetComponent/index.js @@ -36,18 +36,22 @@ export const ActionSheetComponent = ({ }) => { const {colors, changeColorScheme} = useAppContext(); const [focused, setFocused] = useState(false); - const [note, setNote] = useState({ - colors: [], - tags: [], - pinned: false, - favorite: false, - locked: false, - content: { - text: '', - delta: {}, - }, - dateCreated: null, - }); + const [note, setNote] = useState( + item + ? item + : { + colors: [], + tags: [], + pinned: false, + favorite: false, + locked: false, + content: { + text: '', + delta: {}, + }, + dateCreated: null, + }, + ); useEffect(() => { if (item.dateCreated !== null) { @@ -277,10 +281,6 @@ export const ActionSheetComponent = ({ return ( { - console.log(item); - setNote({...item}); - }} style={{ paddingBottom: 15, backgroundColor: colors.bg,