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

add a gallery navigation api event #1258

Closed
wants to merge 2 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,10 @@ export class GalleryContainer extends React.Component {
this.state.options.autoSlideshowContinuousSpeed,
imageMargin: this.state.options.imageMargin,
};
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 @@ -538,6 +542,10 @@ export class GalleryContainer extends React.Component {
this.state.options.autoSlideshowContinuousSpeed,
imageMargin: this.state.options.imageMargin,
};
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
46 changes: 24 additions & 22 deletions packages/gallery/src/components/gallery/proGallery/slideshowView.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@
return {
scrollMarginCorrection: this.getStyles().margin || 0,
_scrollDuration:
scrollDuration || this.props.options.scrollDuration || 400,
scrollDuration ?? this.props.options.scrollDuration ?? 400,
};
}

Expand Down Expand Up @@ -943,37 +943,41 @@
};
createOrGetCustomNavigationPanelAPI = () => {
const isRTL = this.props.options.isRTL;
return (
this.navigationPanelAPI ||
(this.navigationPanelAPI = {
next: () =>
if (!this.navigationPanelAPI) {
this.navigationPanelAPI = {
onGalleryNavigationStart: (handler) => {
this.props.actions.eventsListener(GALLERY_CONSTS.events.GALLERY_NAVIGATION_START, handler);

Check failure on line 949 in packages/gallery/src/components/gallery/proGallery/slideshowView.js

View workflow job for this annotation

GitHub Actions / lint (16.13.0)

Replace `GALLERY_CONSTS.events.GALLERY_NAVIGATION_START,·handler` with `⏎············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[
Expand All @@ -990,18 +994,16 @@
e
);
},
// nextGroup,
// previousItem,
// previousGroup,
toIndex: (itemIdx) =>
this.scrollToIndex({ itemIdx, scrollDuration: 400, isRTL }),
// getCurrentActiveItemIndex,
// getCurrentActiveGroupIndex,
assignIndexChangeCallback: (func) => {
this.navigationPanelCallbackOnIndexChange = func;
navigateToIndex: (itemIdx, animationDuration = 400) => {
this.scrollToIndex({ itemIdx, scrollDuration: animationDuration });
},
})
};
}
this.props.actions.eventsListener(
GALLERY_CONSTS.events.NAVIGATION_API_READY,
this.navigationPanelAPI
);
return this.navigationPanelAPI;
};

getNavigationPanelArray() {
Expand Down
2 changes: 2 additions & 0 deletions packages/lib/src/common/constants/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const EVENTS = {
ITEM_FOCUSED: 'ITEM_FOCUSED',
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;
2 changes: 2 additions & 0 deletions packages/playground/src/components/App/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ export function App() {
break;
case GALLERY_EVENTS.LOAD_MORE_CLICKED:
break;
case GALLERY_EVENTS.NAVIGATION_API_READY:
break;
default:
// console.log({eventName, eventData});
break;
Expand Down
22 changes: 11 additions & 11 deletions packages/playground/src/components/App/PlaygroundNavigationPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ import {
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) {
if(props.navigationPanelAPI.currentIndex() !== activeIdx) {
props.navigationPanelAPI.toIndex(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 @@ -126,23 +126,23 @@ export function NavigationPanel(props) {
return <Step title={item.dto.metadata.title} description={item.dto.metadata.description} />

}
const getAllKindsOfButtons = ({next,triggerItemAction,back,isAbleToNavigateBack, isAbleToNavigateNext, previousItem, previousGroup, toIndex, getCurrentActiveItemIndex, getCurrentActiveGroupIndex}) => {
const getAllKindsOfButtons = ({next,triggerItemClick,back,navigatePreviousEnabled, navigateNextEnabled, previousItem, previousGroup, toIndex, getCurrentActiveItemIndex, getCurrentActiveGroupIndex}) => {
const buttonConfig = [
['Previous item', back, !isAbleToNavigateBack()],
['Previous item', back, !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