Parafia Skoczów
  • 👋Witaj w Parafii Skoczów
  • O APLIKACJI
    • ✨Funkcjonalności
    • 📷Galeria
    • 🛠️Zarządzanie treściami
  • DLA PROGRAMISTÓW
    • 🏗️Przegląd narzędzi
    • ⛪Parafia Skoczów
      • Assets
      • Components
        • Atoms
        • Molecules
        • Organisms
        • Templates
      • Helpers
        • getAnimationProps
        • getData
        • getTransmissionUrl
        • searchContent
        • useModal
      • Hooks
        • useDisablePinchZoom
        • usePinching
        • useSwipe
      • Providers
        • ContentProvider
        • FirebaseProvider
        • PlaylistProvider
      • Utils
      • Views
        • Home
        • Categories
        • Titles
        • Text
        • Playlist
        • Search
      • Cordova
      • Rozwiązywanie problemów
    • 🎶Playlist Maker
      • Assets
      • Components
        • Atoms
        • Molecules
        • Organisms
        • Templates
      • Helpers
      • Hooks
        • useDnd
        • useEdit
        • useName
        • useModal
      • Providers
        • ContentProvider
        • FirebaseProvider
        • NotificationProvider
        • PlaylistProvider
      • Utils
      • Cordova
      • Rozwiązywanie problemów
Powered by GitBook
On this page
  1. DLA PROGRAMISTÓW
  2. Parafia Skoczów
  3. Hooks

usePinching

Zmienia rozmiar czcionki w odpowiedzi na gest powiększania/pomniejszania.

usePinching.js
import { useContext } from 'react';
import { getFromLS } from 'utils/storage';
import { ContentContext } from 'providers/ContentProvider';

export const usePinching = () => {
  const { updateFontSize } = useContext(ContentContext);
  let fontSizeStartGesture;
  let fontSizeInTouchEvent;
  let initialDistance;

  const fontsSize = [
    '12px',
    '13px',
    '14px',
    '15px',
    '16px',
    '17px',
    '18px',
    '19px',
    '20px',
    '21px',
    '22px',
    '23px',
    '24px',
    '25px',
  ];

  const offsetX = (e) => Math.pow(e.touches[0].pageX - e.touches[1].pageX, 2);
  const offsetY = (e) => Math.pow(e.touches[0].pageY - e.touches[1].pageY, 2);
  const getDistance = (e) => Math.round(Math.sqrt(offsetX(e) + offsetY(e)));

  const pinchingStart = (e) => {
    if (e.touches.length === 2) {
      fontSizeStartGesture = getFromLS('textSize');
      initialDistance = getDistance(e);
    }
  };

  const pinchingMove = (e) => {
    if (e.touches.length === 2) {
      const currentDistance = getDistance(e);
      const newfontSize = Math.floor((currentDistance - initialDistance) / 30);
      const fontSize = fontsSize[fontsSize.indexOf(fontSizeStartGesture) + newfontSize];
      if (fontSize !== undefined && fontSize !== fontSizeInTouchEvent) {
        fontSizeInTouchEvent = fontSize;
      }
    }
  };

  const pinchingEnd = (e) => {
    if (e.touches.length === 1) {
      if (fontSizeInTouchEvent) {
        updateFontSize(fontSizeInTouchEvent);
      }
    }
  };

  return {
    pinchingStart,
    pinchingMove,
    pinchingEnd,
  };
};

PrevioususeDisablePinchZoomNextuseSwipe

Last updated 1 year ago

⛪