-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from isoteriksoftware/dev
Implemented a new GalleryItem rendering algorithm
- Loading branch information
Showing
11 changed files
with
178 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,54 @@ | ||
import { useContext } from "react"; | ||
import GalleryContext from "./GalleryContext"; | ||
import { GALLERY_NO_PROVIDER_FLAG, GalleryState } from "./Gallery.types"; | ||
import GalleryItemContext from "../GalleryItem/GalleryItemContext"; | ||
import { GalleryContext } from "./GalleryContext"; | ||
import { GALLERY_NO_PROVIDER_FLAG, UseGalleryReturnType } from "./Gallery.types"; | ||
import { GalleryItemContext } from "../GalleryItem/GalleryItemContext"; | ||
import { GALLERY_ITEM_NO_PROVIDER_FLAG } from "../GalleryItem"; | ||
|
||
/** | ||
* A hook to get the gallery data. | ||
* This hook must be called within a Gallery component. | ||
* | ||
* @returns {GalleryState} The gallery state data. | ||
* @returns {UseGalleryReturnType} The gallery state data. | ||
*/ | ||
export const useGallery = (): GalleryState => { | ||
const data = useContext(GalleryContext); | ||
export const useGallery = (): UseGalleryReturnType => { | ||
const galleryState = useContext(GalleryContext); | ||
|
||
if (data === GALLERY_NO_PROVIDER_FLAG) { | ||
if (galleryState === GALLERY_NO_PROVIDER_FLAG) { | ||
throw new Error("useGallery must be called within a Gallery"); | ||
} | ||
|
||
const itemData = useContext(GalleryItemContext); | ||
if (itemData !== GALLERY_ITEM_NO_PROVIDER_FLAG) { | ||
data.item.itemIndex = itemData.itemIndex; | ||
const galleryItemState = useContext(GalleryItemContext); | ||
if (galleryItemState !== GALLERY_ITEM_NO_PROVIDER_FLAG) { | ||
galleryState.item.itemIndex = galleryItemState.itemIndex; | ||
} | ||
|
||
return data; | ||
const { | ||
itemCount, | ||
item: { | ||
width, | ||
height, | ||
radialSegments, | ||
heightSegments, | ||
innerRadiusPercent, | ||
sectionAngle, | ||
outerRadius, | ||
innerRadius, | ||
itemIndex, | ||
}, | ||
} = galleryState; | ||
|
||
return { | ||
itemCount, | ||
item: { | ||
width, | ||
height, | ||
radialSegments, | ||
heightSegments, | ||
innerRadiusPercent, | ||
sectionAngle, | ||
outerRadius, | ||
innerRadius, | ||
itemIndex, | ||
}, | ||
}; | ||
}; |
Oops, something went wrong.