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

Navigation API- Add GalleryNavigationStart event #1212

Merged
merged 5 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,10 @@ export class GalleryContainer extends React.Component {
this.state.options[optionsMap.behaviourParams.gallery.horizontal.autoSlide.speed],
itemSpacing: this.state.options[optionsMap.layoutParams.structure.itemSpacing],
};
this.eventsListener(GALLERY_CONSTS.events.GALLERY_NAVIGATION_START, {
current: 'scrollToItem',
scrollParams,
});
this.currentScrollData = scrollToItemImp(scrollParams);
return this.currentScrollData.scrollDeffered.promise.then(() => {
this.currentScrollData = null;
Expand Down Expand Up @@ -485,6 +489,10 @@ export class GalleryContainer extends React.Component {
this.state.options[optionsMap.behaviourParams.gallery.horizontal.autoSlide.speed],
itemSpacing: this.state.options[optionsMap.layoutParams.structure.itemSpacing],
};
this.eventsListener(GALLERY_CONSTS.events.GALLERY_NAVIGATION_START, {
current: 'scrollToGroup',
scrollParams,
});
this.currentScrollData = scrollToGroupImp(scrollParams);
return this.currentScrollData.scrollDeffered.promise.then(() => {
this.currentScrollData = null;
Expand Down
34 changes: 20 additions & 14 deletions packages/gallery/src/components/gallery/proGallery/slideshowView.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ class SlideshowView extends React.Component {
return {
scrollMarginCorrection: this.getStyles().margin || 0,
_scrollDuration:
scrollDuration || this.props.options.behaviourParams_gallery_horizontal_navigationDuration || 400,
scrollDuration ?? this.props.options.behaviourParams_gallery_horizontal_navigationDuration ?? 400,
};
}

Expand Down Expand Up @@ -862,34 +862,39 @@ class SlideshowView extends React.Component {
GALLERY_CONSTS[optionsMap.behaviourParams.gallery.layoutDirection].RIGHT_TO_LEFT;
if (!this.navigationPanelAPI) {
this.navigationPanelAPI = {
next: () =>
onGalleryNavigationStart: (handler) => {
this.props.actions.eventsListener(GALLERY_CONSTS.events.GALLERY_NAVIGATION_START, handler);
},
next: () => {
this.next({
scrollDuration: 400,
isKeyboardNavigation: false,
isAutoTrigger: false,
avoidIndividualNavigation: false,
isContinuousScrolling: false,
direction: isRTL ? -1 : 1,
}),
back: () =>
});
},
previous: () => {
this.next({
scrollDuration: 400,
isKeyboardNavigation: false,
isAutoTrigger: false,
avoidIndividualNavigation: false,
isContinuousScrolling: false,
direction: isRTL ? 1 : -1,
}),
isAbleToNavigateNext: () => {
});
},
navigateNextEnabled: () => {
return isRTL ? !this.state.hideLeftArrow : !this.state.hideRightArrow;
},
isAbleToNavigateBack: () => {
navigatePreviousEnabled: () => {
return isRTL ? !this.state.hideRightArrow : !this.state.hideLeftArrow;
},
getActiveItemIndex: () => {
currentIndex: () => {
return this.state.activeIndex;
},
triggerItemAction: (e, { itemIndex = this.state.activeIndex } = {}) => {
triggerItemClick: (e, { itemIndex = this.state.activeIndex } = {}) => {
const galleryConfig = this.createGalleryConfig();
const item = this.props.galleryStructure.galleryItems[itemIndex % this.props.totalItemsCount];
const props = item?.renderProps({
Expand All @@ -902,13 +907,14 @@ class SlideshowView extends React.Component {
// nextGroup,
noam-heller1 marked this conversation as resolved.
Show resolved Hide resolved
// previousItem,
// previousGroup,
toIndex: (itemIdx, animationDuration = 400) =>
this.scrollToIndex({ itemIdx, scrollDuration: animationDuration }),
navigateToIndex: (itemIdx, animationDuration = 400) => {
this.scrollToIndex({ itemIdx, scrollDuration: animationDuration });
},
// getCurrentActiveItemIndex,
// getCurrentActiveGroupIndex,
assignIndexChangeCallback: (func) => {
this.navigationPanelCallbackOnIndexChange = func;
},
// assignIndexChangeCallback: (func) => {
// this.navigationPanelCallbackOnIndexChange = func;
// },
};
}
this.props.actions.eventsListener(GALLERY_CONSTS.events.NAVIGATION_API_READY, this.navigationPanelAPI);
Expand Down
1 change: 1 addition & 0 deletions packages/lib/src/common/constants/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const EVENTS = {
ITEM_LOST_FOCUS: 'ITEM_LOST_FOCUS',
GALLERY_SCROLLED: 'GALLERY_SCROLLED',
NAVIGATION_API_READY: 'NAVIGATION_API_READY',
GALLERY_NAVIGATION_START: 'GALLERY_NAVIGATION_START',
} as const;

export default EVENTS;
32 changes: 16 additions & 16 deletions packages/playground/src/components/App/PlaygroundNavigationPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ import { optionsMap, GALLERY_CONSTS } from 'pro-gallery-lib';
const { Step } = Steps;

export function NavigationPanel(props) {
const [activeIdx, setActiveIndex] = useState(props.navigationPanelAPI.getActiveItemIndex());
const [activeIdx, setActiveIndex] = useState(props.navigationPanelAPI.currentIndex());
props.navigationPanelAPI.assignIndexChangeCallback(setActiveIndex);
useEffect(() => {
if (props.navigationPanelAPI.getActiveItemIndex() !== activeIdx) {
props.navigationPanelAPI.toIndex(activeIdx);
if (props.navigationPanelAPI.currentIndex() !== activeIdx) {
props.navigationPanelAPI.navigateToIndex(activeIdx);
}
}, [activeIdx, props.navigationPanelAPI]);

const APINavigationPanel = (props) => {
const activeIdx = props.navigationPanelAPI.getActiveItemIndex();
const activeIdx = props.navigationPanelAPI.currentIndex();
const percent = (activeIdx + 1) / props.totalItemsCount;
const totalForProgress = props.totalItemsCount === Infinity ? 100 : props.totalItemsCount;
let containerStyles = {
Expand Down Expand Up @@ -141,36 +141,36 @@ export function NavigationPanel(props) {
};
const getAllKindsOfButtons = ({
next,
triggerItemAction,
back,
isAbleToNavigateBack,
isAbleToNavigateNext,
toIndex,
triggerItemClick,
previous,
navigatePreviousEnabled,
navigateNextEnabled,
navigateToIndex,
}) => {
const buttonConfig = [
['Previous item', back, !isAbleToNavigateBack()],
['Previous item', previous, !navigatePreviousEnabled()],
[
'Next item',
async () => {
console.time('SCROLLING NEXT');
await next(); //Scrolling functions are async.
console.timeEnd('SCROLLING NEXT');
},
!isAbleToNavigateNext(),
!navigateNextEnabled(),
],
[
'toIndex 3',
async () => {
console.time('SCROLLING to item 3');
await toIndex(3); //Scrolling functions are async.
await navigateToIndex(3); //Scrolling functions are async.
console.timeEnd('SCROLLING to item 3');
},
false,
],
['toIndex 0', () => toIndex(0), false],
['toIndex 10', () => toIndex(10), false],
['ItemAction', (e) => triggerItemAction(e), false],
['Item 3 action', (e) => triggerItemAction(e, { itemIndex: 3 }), false],
['toIndex 0', () => navigateToIndex(0), false],
['toIndex 10', () => navigateToIndex(10), false],
['ItemAction', (e) => triggerItemClick(e), false],
['Item 3 action', (e) => triggerItemClick(e, { itemIndex: 3 }), false],
];
return (
<div class="navigation-panel-buttons">
Expand Down
Loading