Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/cawfree/react-native-picture-puzzle

⚛️ 🧩 A picture puzzle component.
https://github.com/cawfree/react-native-picture-puzzle

game picture puzzle react-native

Last synced: 3 months ago
JSON representation

⚛️ 🧩 A picture puzzle component.

Awesome Lists containing this project

README

        

# react-native-picture-puzzle
⚛️ 🧩 A picture puzzle component. Supports [**Android**](https://reactnative.dev), [**iOS**](https://reactnative.dev) and the [**Web**](https://github.com/necolas/react-native-web).

[🎬 **demo**](https://twitter.com/cawfree/status/1350268277143068673)



## 🚀 getting started

Using [**Yarn**](https://yarnpkg.com):

```sh
yarn add react-native-picture-puzzle
```

## ✍️ usage

```typescript
import React from 'react';
import { PicturePuzzle, PuzzlePieces } from 'react-native-picture-puzzle';

export default function App() {
const [hidden, setHidden] = React.useState(0); // piece to obscure
const [pieces, setPieces] = React.useState([0, 1, 2, 3, 4, 5, 6, 7, 8]);
const source = React.useMemo(() => ({
uri: 'https://pbs.twimg.com/profile_images/1180062941162479616/W8XdhKTG_400x400.jpg',
}), []);
const renderLoading = React.useCallback((): JSX.Element => , []);
const onChange = React.useCallback((nextPieces: PuzzlePieces, nextHidden: number | null): void => {
setPieces(nextPieces);
setHidden(nextHidden);
}, [setPieces, setHidden]);
return (

);
}
```

## 🦄 types

```typescript
export type PuzzlePiece = number;

export type PuzzlePieces = readonly PuzzlePiece[];

export enum MoveDirection {
BOTTOM = 'bottom',
LEFT = 'left',
RIGHT = 'right',
TOP = 'top',
}

export type PicturePuzzleProps = ImageProps & {
readonly hidden: number | null;
readonly size: number;
readonly pieces: PuzzlePieces;
readonly source: ImageURISource | number;
readonly renderLoading?: () => JSX.Element;
readonly onChange?: (nextPieces: PuzzlePieces, nextHidden: number | null) => void;
};
```

## ✌️ license
[**MIT**](./LICENSE)