Skip to content
This repository was archived by the owner on Nov 24, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .babelrc

This file was deleted.

53 changes: 0 additions & 53 deletions .eslintrc

This file was deleted.

2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @generated by expo-module-scripts
module.exports = require("expo-module-scripts/eslintrc.base.js");
15 changes: 13 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
node_modules/**/*
.expo/*
node_modules/
.expo/
dist/
npm-debug.*
*.jks
*.p8
*.p12
*.key
*.mobileprovision
*.orig.*
web-build/

# macOS
.DS_Store
5 changes: 0 additions & 5 deletions .npmignore

This file was deleted.

1 change: 0 additions & 1 deletion .watchmanconfig

This file was deleted.

21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

189 changes: 47 additions & 142 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,172 +1,77 @@
# expo-pixi

Tools to use [Pixi.js](http://www.pixijs.com/) in Expo!
[Pixi.js V4](https://pixijs.download/v4.8.9/docs/) for Expo.

To get started: `yarn add expo-pixi` in your Expo project and import it with
`import ExpoPixi from 'expo-pixi';`.
## Installation

```bash
$ npm install @Bartozzz/expo-pixi
```

## Side-Effects

To use Pixi.js with Expo & React Native you will want to import a modified version of Pixi.js like so:

```js

// ✅
import { PIXI } from 'expo-pixi';
```bash
$ yarn add @Bartozzz/expo-pixi
```

// ❌
import * as PIXI from 'pixi.js';
Additionally, you'll need to install the following dependencies:

```bash
$ expo install expo-gl expo-asset
```

Now you can create a new Application the way you would on the web, but be sure to pass in a `WebGLRenderingContext`.

```js
## Usage

```ts
// ✅
const app = new PIXI.Application({ context });
import { PIXI } from "expo-pixi";

// ❌
const app = ExpoPIXI.application({ context });

import * as PIXI from "pixi.js";
```

Finally, because of the way React Native currently works you must load in assets asynchronously.

```js

/*
* Accepts:
* - Expo.Asset: import { Asset } from 'expo-asset'; Asset.fromModule( ... );
* - URL (with file extension): 'http://i.imgur.com/uwrbErh.png'
* - Static Resource: require('./icon.png')
*/
Now you can create a new `Application` the way you would on the web, but be sure to pass in a `WebGLRenderingContext` and pass all the configuration options in the first argument:

```ts
// ✅
const sprite = await PIXI.Sprite.fromExpoAsync('http://i.imgur.com/uwrbErh.png');

// OR

const texture = await PIXI.Texture.fromExpoAsync('http://i.imgur.com/uwrbErh.png');
const app = new PIXI.Application({ width, height, context });

// ❌
const sprite = await ExpoPIXI.spriteAsync('http://i.imgur.com/uwrbErh.png');

// OR

const texture = await ExpoPIXI.textureAsync('http://i.imgur.com/uwrbErh.png');
const app = new PIXI.application(width, height);
```

Using web syntax will return a `Promise`, and throw a warning. It's bad practice, but if the asset is loaded already, this will work without throwing a warning.

```js
const sprite = await PIXI.Sprite.from(require('./icon.png'));

// > console.warning(PIXI.Sprite.from(asset: ${typeof asset}) is not supported. Returning a Promise!);

// OR
Finally, because of the way React Native currently works you must load in assets asynchronously.

const texture = await PIXI.Texture.from(require('./icon.png'));
```ts
// ✅
const texture = await PIXI.Texture.from(expoAsset);
const texture = await PIXI.Texture.from(require("../assets/monster.png"));
const texture = await PIXI.Texture.from("https://cdn.example.com/monster.png");

// > console.warning(PIXI.Texture.from(asset: ${typeof asset}) is not supported. Returning a Promise!);
// ✅
const sprite = await PIXI.Sprite.from(texture);
const sprite = await PIXI.Sprite.from(expoAsset);
const sprite = await PIXI.Sprite.from(require("../assets/monster.png"));
const sprite = await PIXI.Sprite.from("https://cdn.example.com/monster.png");
```

## Functions

### `ExpoPixi.application(props): PIXI.Application`

> Deprecated: Use `new PIXI.Application({ context });`

A helper function to create a `PIXI.Application` from a WebGL context.
EXGL knows to end a frame when the function: `endFrameEXP` is called on the GL context.

**`context` is the only required prop.**

[Learn more about PIXI.Application props](http://pixijs.download/dev/docs/PIXI.Application.html)

### `ExpoPixi.textureAsync(resource: any): Promise`

> Deprecated: Use `PIXI.Texture.fromExpoAsync(resource);`

### `ExpoPixi.spriteAsync(resource: any): Promise`

> Deprecated: Use `PIXI.Sprite.fromExpoAsync(resource);`

a helper function to resolve the asset passed in.
`textureAsync` accepts:

* localUri: string | ex: "file://some/path/image.png"
* static resource: number | ex: require('./image.png')
* remote url: string | ex: "https://www.something.com/image.png"
* asset-library: string (iOS `CameraRoll`) | ex: "asset-library://some/path/image.png"
* Expo Asset: Expo.Asset | learn more: https://docs.expo.io/versions/latest/guides/assets.html

You cannot send in relative string paths as Metro Bundler looks for static resources.

---

### `ExpoPixi.sprite({ localUri: string, width: number, height: number }): PIXI.Sprite`

> Deprecated: Use `PIXI.Sprite.from(resource);`

### `ExpoPixi.texture({ localUri: string, width: number, height: number }): PIXI.Texture`

> Deprecated: Use `PIXI.Texture.from(resource);`

Pixi.js does a type check so we wrap our asset in a `HTMLImageElement` shim.

## `ExpoPixi.Sketch`

A component used for drawing smooth signatures and sketches.

**See the sketch example on how to save the images!**

> Notice: the edges and ends are not rounded as this is not supported in PIXI yet: [Issue](https://github.com/pixijs/pixi.js/issues/1637)

#### Props

| Property | Type | Default | Description |
| ----------- | :-------------------------: | :------: | ----------------------------------------------- |
| strokeColor | number | 0x000000 | Color of the lines |
| strokeWidth | number | 10 | Weight of the lines |
| strokeAlpha | number | 1 | Opacity of the lines |
| onChange | () => PIXI.Renderer | null | Invoked whenever a user is done drawing a line |
| onReady | () => WebGLRenderingContext | null | Invoked when the GL context is ready to be used |

## `ExpoPixi.FilterImage`

A Image component that uses PIXI.Filter

#### Props

| Property | Type | Default | Description |
| ---------- | :------------------------: | :-----: | ---------------------------------------------------------------------------- |
| resizeMode | string | null | Currently only supports `cover`, and `contain` |
| filters | Array<PIXI.Filter> | null | Array of filters to apply to the image |
| source | number, string, Expo.Asset | null | Source can be a static resource, image url (not `{uri}`), or an `Expo.Asset` |

## Example

**[Snack](https://snack.expo.io/@bacon/base-pixi.js)**
You can find plenty of examples in the `example/` application. A minimal working example is:

```js
import React from 'react';
import Expo from 'expo';
import { PIXI } from 'expo-pixi';

export default () => (
<Expo.GLView
style={{ flex: 1 }}
onContextCreate={async context => {
const app = new PIXI.Application({ context });
const sprite = await PIXI.Sprite.fromExpoAsync(
'http://i.imgur.com/uwrbErh.png',
);
app.stage.addChild(sprite);
}}
/>
);
import { GLView } from "expo-gl";
import { PIXI } from "@Bartozzz/expo-pixi";

export function App() {
return (
<Expo.GLView
style={{ flex: 1 }}
onContextCreate={async (context) => {
const app = new PIXI.Application({ context });
const sprite = PIXI.Sprite.from(require("../assets/monster.png"));

app.stage.addChild(sprite);
}}
/>
);
}
```

[![NPM](https://nodei.co/npm/expo-pixi.png)](https://nodei.co/npm/expo-pixi/)
2 changes: 2 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @generated by expo-module-scripts
module.exports = require("expo-module-scripts/babel.config.base");
1 change: 1 addition & 0 deletions build/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./pixi";
2 changes: 2 additions & 0 deletions build/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading