mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-21 14:09:34 +01:00
remove unecessary state updating
This commit is contained in:
@@ -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,6 +85,7 @@ export default class ActionSheet extends Component {
|
||||
} else {
|
||||
this.customComponentHeight = height;
|
||||
|
||||
setTimeout(() => {
|
||||
this._scrollTo(
|
||||
gestureEnabled
|
||||
? this.customComponentHeight * initialOffsetFromBottom +
|
||||
@@ -92,15 +93,14 @@ export default class ActionSheet extends Component {
|
||||
bounceOffset
|
||||
: this.customComponentHeight + bounceOffset,
|
||||
);
|
||||
this.setState({
|
||||
layoutHasCalled: true,
|
||||
});
|
||||
}, 300);
|
||||
|
||||
this.layoutHasCalled = true;
|
||||
}
|
||||
};
|
||||
|
||||
_onScrollBeginDrag = event => {
|
||||
let verticalOffset = event.nativeEvent.contentOffset.y;
|
||||
|
||||
this.prevScroll = verticalOffset;
|
||||
};
|
||||
|
||||
|
||||
@@ -36,7 +36,10 @@ export const ActionSheetComponent = ({
|
||||
}) => {
|
||||
const {colors, changeColorScheme} = useAppContext();
|
||||
const [focused, setFocused] = useState(false);
|
||||
const [note, setNote] = useState({
|
||||
const [note, setNote] = useState(
|
||||
item
|
||||
? item
|
||||
: {
|
||||
colors: [],
|
||||
tags: [],
|
||||
pinned: false,
|
||||
@@ -47,7 +50,8 @@ export const ActionSheetComponent = ({
|
||||
delta: {},
|
||||
},
|
||||
dateCreated: null,
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (item.dateCreated !== null) {
|
||||
@@ -277,10 +281,6 @@ export const ActionSheetComponent = ({
|
||||
|
||||
return (
|
||||
<View
|
||||
onLayout={() => {
|
||||
console.log(item);
|
||||
setNote({...item});
|
||||
}}
|
||||
style={{
|
||||
paddingBottom: 15,
|
||||
backgroundColor: colors.bg,
|
||||
|
||||
Reference in New Issue
Block a user