remove unecessary state updating

This commit is contained in:
ammarahm-ed
2020-01-15 20:20:53 +05:00
parent 3155541fa4
commit e6e1b93fc5
2 changed files with 32 additions and 32 deletions

View File

@@ -36,6 +36,7 @@ export default class ActionSheet extends Component {
this.scrollAnimationEndValue; this.scrollAnimationEndValue;
this.hasBounced; this.hasBounced;
this.scrollViewRef; this.scrollViewRef;
this.layoutHasCalled = false;
} }
_setModalVisible = () => { _setModalVisible = () => {
@@ -55,26 +56,25 @@ export default class ActionSheet extends Component {
this.setState( this.setState(
{ {
modalVisible: false, modalVisible: false,
layoutHasCalled: false,
}, },
() => { () => {
this.layoutHasCalled = false;
if (typeof this.props.onClose === 'function') this.props.onClose(); if (typeof this.props.onClose === 'function') this.props.onClose();
}, },
); );
}, 150); }, 500);
}; };
_showModal = event => { _showModal = event => {
let {gestureEnabled, bounceOffset, initialOffsetFromBottom} = this.props; let {gestureEnabled, bounceOffset, initialOffsetFromBottom} = this.props;
let addFactor = deviceHeight * 0.1; let addFactor = deviceHeight * 0.1;
let height = event.nativeEvent.layout.height; let height = event.nativeEvent.layout.height;
console.log('layout called again'); if (this.layoutHasCalled) {
if (this.state.layoutHasCalled) {
let diff; let diff;
if (height > this.customComponentHeight) { if (height > this.customComponentHeight) {
diff = height - this.customComponentHeight; diff = height - this.customComponentHeight;
this._scrollTo(this.prevScroll + diff); this._scrollTo(this.prevScroll + diff);
console.log(this.prevScroll);
this.customComponentHeight = height; this.customComponentHeight = height;
} else { } else {
diff = this.customComponentHeight - height; diff = this.customComponentHeight - height;
@@ -85,6 +85,7 @@ export default class ActionSheet extends Component {
} else { } else {
this.customComponentHeight = height; this.customComponentHeight = height;
setTimeout(() => {
this._scrollTo( this._scrollTo(
gestureEnabled gestureEnabled
? this.customComponentHeight * initialOffsetFromBottom + ? this.customComponentHeight * initialOffsetFromBottom +
@@ -92,15 +93,14 @@ export default class ActionSheet extends Component {
bounceOffset bounceOffset
: this.customComponentHeight + bounceOffset, : this.customComponentHeight + bounceOffset,
); );
this.setState({ }, 300);
layoutHasCalled: true,
}); this.layoutHasCalled = true;
} }
}; };
_onScrollBeginDrag = event => { _onScrollBeginDrag = event => {
let verticalOffset = event.nativeEvent.contentOffset.y; let verticalOffset = event.nativeEvent.contentOffset.y;
this.prevScroll = verticalOffset; this.prevScroll = verticalOffset;
}; };

View File

@@ -36,7 +36,10 @@ export const ActionSheetComponent = ({
}) => { }) => {
const {colors, changeColorScheme} = useAppContext(); const {colors, changeColorScheme} = useAppContext();
const [focused, setFocused] = useState(false); const [focused, setFocused] = useState(false);
const [note, setNote] = useState({ const [note, setNote] = useState(
item
? item
: {
colors: [], colors: [],
tags: [], tags: [],
pinned: false, pinned: false,
@@ -47,7 +50,8 @@ export const ActionSheetComponent = ({
delta: {}, delta: {},
}, },
dateCreated: null, dateCreated: null,
}); },
);
useEffect(() => { useEffect(() => {
if (item.dateCreated !== null) { if (item.dateCreated !== null) {
@@ -277,10 +281,6 @@ export const ActionSheetComponent = ({
return ( return (
<View <View
onLayout={() => {
console.log(item);
setNote({...item});
}}
style={{ style={{
paddingBottom: 15, paddingBottom: 15,
backgroundColor: colors.bg, backgroundColor: colors.bg,