Skip to content
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

Fix weird UI bug #305

Merged
merged 2 commits into from
Apr 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 30 additions & 13 deletions src/Event/Event.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,34 @@ const Event = ({
// https://docs.swmansion.com/react-native-reanimated/docs/api/miscellaneous/runOnJS
const onPressWrapper = () => onPress && onPress(event);
const onLongPressWrapper = () => onLongPress && onLongPress(event);
const onDragWrapper = (...args) => onDrag && onDrag(event, ...args);
const onEditWrapper = (params) => onEdit && onEdit(event, params);
const onDragWrapper = (dx, dy) => {
if (!onDrag) return;

const newX = left + dx;
const newY = top + dy;
onDrag(event, newX, newY, width);
};
const onEditWrapper = (side, resizedAmount) => {
if (!onEdit) return;

const params = {};
switch (side) {
case 'top':
params.top = top + resizedAmount;
break;
case 'bottom':
params.bottom = top + height + resizedAmount;
break;
case 'left':
params.left = left + resizedAmount;
break;
case 'right':
params.right = left + width + resizedAmount;
break;
default:
}
onEdit(event, params);
};

const resizeByEdit = {
bottom: useSharedValue(0),
Expand Down Expand Up @@ -173,11 +199,7 @@ const Event = ({
currentLeft.value += translationX;
translatedByDrag.value = { x: 0, y: 0 };

runOnJS(onDragWrapper)(
currentLeft.value,
currentTop.value,
currentWidth.value,
);
runOnJS(onDragWrapper)(translationX, translationY);
})
.onFinalize(() => {
dragStatus.value = DRAG_STATUS.STATIC;
Expand Down Expand Up @@ -272,30 +294,25 @@ const Event = ({
const resizedAmount = resizeByEdit[side].value;
resizeByEdit[side].value = 0;

const params = {};
switch (side) {
case 'top':
currentTop.value += resizedAmount;
currentHeight.value -= resizedAmount;
params.top = currentTop.value;
break;
case 'bottom':
currentHeight.value += resizedAmount;
params.bottom = currentTop.value + currentHeight.value;
break;
case 'left':
currentLeft.value += resizedAmount;
currentWidth.value -= resizedAmount;
params.left = currentLeft.value;
break;
case 'right':
currentWidth.value += resizedAmount;
params.right = currentLeft.value + currentWidth.value;
break;
default:
}

runOnJS(onEditWrapper)(params);
runOnJS(onEditWrapper)(side, resizedAmount);
});

return (
Expand Down
2 changes: 1 addition & 1 deletion src/Events/Events.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class Events extends PureComponent {
return;
}

const halfDayAnchor = Math.min(eventWidth, this.props.dayWidth / 2);
const halfDayAnchor = Math.min(eventWidth, this.props.dayWidth) / 2;

// NOTE: The point (newX, newY) is in the eventsColumn coordinates
const movedDays = this.xToDayIndex(newX + halfDayAnchor);
Expand Down