index.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import React, { useEffect } from "react";
  2. import { InitializeApp } from "../components/InitializeApp";
  3. import App from "../components/App";
  4. import "../css/app.scss";
  5. import "../css/styles.scss";
  6. import { ExcalidrawProps } from "../types";
  7. import { IsMobileProvider } from "../is-mobile";
  8. const Excalidraw = React.memo(
  9. (props: ExcalidrawProps) => {
  10. const {
  11. width,
  12. height,
  13. onChange,
  14. initialData,
  15. user,
  16. onUsernameChange,
  17. } = props;
  18. useEffect(() => {
  19. // Block pinch-zooming on iOS outside of the content area
  20. const handleTouchMove = (event: TouchEvent) => {
  21. // @ts-ignore
  22. if (typeof event.scale === "number" && event.scale !== 1) {
  23. event.preventDefault();
  24. }
  25. };
  26. document.addEventListener("touchmove", handleTouchMove, {
  27. passive: false,
  28. });
  29. return () => {
  30. document.removeEventListener("touchmove", handleTouchMove);
  31. };
  32. }, []);
  33. return (
  34. <InitializeApp>
  35. <IsMobileProvider>
  36. <App
  37. width={width}
  38. height={height}
  39. onChange={onChange}
  40. initialData={initialData}
  41. user={user}
  42. onUsernameChange={onUsernameChange}
  43. />
  44. </IsMobileProvider>
  45. </InitializeApp>
  46. );
  47. },
  48. (prevProps: ExcalidrawProps, nextProps: ExcalidrawProps) => {
  49. const { initialData: prevInitialData, user: prevUser, ...prev } = prevProps;
  50. const { initialData: nextInitialData, user: nextUser, ...next } = nextProps;
  51. const prevKeys = Object.keys(prevProps) as (keyof typeof prev)[];
  52. const nextKeys = Object.keys(nextProps) as (keyof typeof next)[];
  53. return (
  54. prevUser?.name === nextUser?.name &&
  55. prevKeys.length === nextKeys.length &&
  56. prevKeys.every((key) => prev[key] === next[key])
  57. );
  58. },
  59. );
  60. export default Excalidraw;