UNPKG

stream-chat-react-native-core

Version:

The official React Native and Expo components for Stream Chat, a service for building chat applications

53 lines 2.15 kB
Object.defineProperty(exports, "__esModule", { value: true }); exports.useCurrentImageHeight = void 0; var _react = require("react"); var _reactNative = require("react-native"); var _reactNativeReanimated = require("react-native-reanimated"); var _types = require("../../../types/types"); var useCurrentImageHeight = ({ assets, fullWindowHeight, fullWindowWidth, imageGalleryStateStore }) => { var currentImageHeight = (0, _reactNativeReanimated.useSharedValue)(fullWindowHeight); (0, _react.useEffect)(() => { var latestToken = 0; var compute = index => { var currentToken = ++latestToken; var photo = assets[index]; if (photo != null && photo.original_height && photo != null && photo.original_width) { var h = Math.floor(photo.original_height * (fullWindowWidth / photo.original_width)); currentImageHeight.value = h > fullWindowHeight ? fullWindowHeight : h; return; } if (photo != null && photo.uri && photo.type === _types.FileTypes.Image) { _reactNative.Image.getSize(photo.uri, (width, height) => { if (currentToken !== latestToken) return; if (!width || !height) { currentImageHeight.value = fullWindowHeight; return; } var imageHeight = Math.floor(height * (fullWindowWidth / width)); currentImageHeight.value = imageHeight > fullWindowHeight ? fullWindowHeight : imageHeight; }, () => { if (currentToken !== latestToken) return; currentImageHeight.value = fullWindowHeight; }); return; } currentImageHeight.value = fullWindowHeight; }; compute(imageGalleryStateStore.state.getLatestValue().currentIndex); return imageGalleryStateStore.state.subscribeWithSelector(state => ({ currentIndex: state.currentIndex }), ({ currentIndex }) => compute(currentIndex)); }, [assets, fullWindowHeight, fullWindowWidth, currentImageHeight, imageGalleryStateStore]); return currentImageHeight; }; exports.useCurrentImageHeight = useCurrentImageHeight; //# sourceMappingURL=useCurrentImageHeight.js.map