@livelike/react-native
Version:
LiveLike React Native package
52 lines (51 loc) • 1.64 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useEmojiSlider = void 0;
var _react = require("react");
/**
* @description useEmojiSlider hook provides state logic and effects for LLEmojiSlider component
*/
const useEmojiSlider = _ref => {
let {
thumbImages,
onValueChange,
onSlidingComplete,
initialValue,
value
} = _ref;
const [sliderInput, setSliderInput] = (0, _react.useState)(value);
const [thumbImg, setThumbImg] = (0, _react.useState)('');
const onValueChangeHandler = (0, _react.useCallback)(_ref2 => {
let [value] = _ref2;
for (let i = 0; i < thumbImages.length; i++) {
var _thumbImages;
const min = thumbImages[i].min;
const max = ((_thumbImages = thumbImages[i + 1]) === null || _thumbImages === void 0 ? void 0 : _thumbImages.min) ?? 1;
if (value >= min && value <= max && thumbImages[i].imageUrl !== thumbImg) {
setThumbImg(thumbImages[i].imageUrl);
return setSliderInput(value);
}
}
onValueChange === null || onValueChange === void 0 || onValueChange(value);
}, [thumbImages, thumbImg]);
const onSlidingCompleteHandler = (0, _react.useCallback)(_ref3 => {
let [value] = _ref3;
setSliderInput(value);
onSlidingComplete(value);
}, []);
(0, _react.useEffect)(() => {
if (!thumbImg && initialValue) {
onValueChangeHandler([initialValue]);
}
}, [initialValue, thumbImg]);
return {
sliderInput,
thumbImg,
onSlidingCompleteHandler,
onValueChangeHandler
};
};
exports.useEmojiSlider = useEmojiSlider;
//# sourceMappingURL=useEmojiSlider.js.map