-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Example@lint] Change: Run yarn lint --fix
- Loading branch information
Showing
22 changed files
with
588 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,135 @@ | ||
import * as React from "react" | ||
import {Image, Text} from "react-native" | ||
import styles, { ImageResultProps } from "../App.styles" | ||
import {noop} from "../utils" | ||
import PhotoManipulator, {FlipMode, PhotoBatchOperations, MimeType, RotationMode} from "react-native-photo-manipulator" | ||
import {IMAGE, OVERLAY} from "./settings" | ||
import * as React from 'react'; | ||
import {Image, Text} from 'react-native'; | ||
import styles, {ImageResultProps} from '../App.styles'; | ||
import {noop} from '../utils'; | ||
import PhotoManipulator, { | ||
FlipMode, | ||
PhotoBatchOperations, | ||
MimeType, | ||
RotationMode, | ||
} from 'react-native-photo-manipulator'; | ||
import {IMAGE, OVERLAY} from './settings'; | ||
|
||
export default React.memo(function ExampleBatch() { | ||
const [image, setImage] = React.useState<string|null>(null); | ||
const [imagePng, setImagePng] = React.useState<string|null>(null); | ||
const [image, setImage] = React.useState<string | null>(null); | ||
const [imagePng, setImagePng] = React.useState<string | null>(null); | ||
|
||
React.useEffect(() => { | ||
const operation = async () => { | ||
setImage(await PhotoManipulator.batch(IMAGE, operations(), { x: 40, y: 5, width: 600, height: 400 }, { width: 300, height: 200 }, 30)) | ||
setImagePng(await PhotoManipulator.batch(IMAGE, operations(), { x: 40, y: 5, width: 600, height: 400 }, undefined, undefined, MimeType.PNG)) | ||
setImage( | ||
await PhotoManipulator.batch( | ||
IMAGE, | ||
operations(), | ||
{x: 40, y: 5, width: 600, height: 400}, | ||
{width: 300, height: 200}, | ||
30, | ||
), | ||
); | ||
setImagePng( | ||
await PhotoManipulator.batch( | ||
IMAGE, | ||
operations(), | ||
{x: 40, y: 5, width: 600, height: 400}, | ||
undefined, | ||
undefined, | ||
MimeType.PNG, | ||
), | ||
); | ||
}; | ||
|
||
operation().then(noop).catch(console.log); | ||
}, []); | ||
|
||
return <> | ||
{ typeof image === "string" ? <Text style={styles.exampleDescription}>Crop & Resize</Text> : null } | ||
{ typeof image === "string" ? <Image testID="batchResult" {...ImageResultProps} source={{ uri: image}} /> : null } | ||
{ typeof imagePng === "string" ? <Text style={styles.exampleDescription}>Crop Only</Text> : null } | ||
{ typeof imagePng === "string" ? <Image testID="batchResultPng" {...ImageResultProps} source={{ uri: imagePng}} /> : null } | ||
return ( | ||
<> | ||
{typeof image === 'string' ? ( | ||
<Text style={styles.exampleDescription}>Crop & Resize</Text> | ||
) : null} | ||
{typeof image === 'string' ? ( | ||
<Image | ||
testID="batchResult" | ||
{...ImageResultProps} | ||
source={{uri: image}} | ||
/> | ||
) : null} | ||
{typeof imagePng === 'string' ? ( | ||
<Text style={styles.exampleDescription}>Crop Only</Text> | ||
) : null} | ||
{typeof imagePng === 'string' ? ( | ||
<Image | ||
testID="batchResultPng" | ||
{...ImageResultProps} | ||
source={{uri: imagePng}} | ||
/> | ||
) : null} | ||
</> | ||
); | ||
|
||
function operations(): PhotoBatchOperations[] { | ||
return [ | ||
{ operation: "flip", mode: FlipMode.Horizontal }, | ||
{ operation: "rotate", mode: RotationMode.R180 }, | ||
{ operation: "text", options: { text: "Test Print Text", color: "black", textSize: 30, fontName: "Girassol-Regular", position: { x: 80, y: 30 }, thickness: 4 } }, | ||
{ operation: "text", options: { text: "Test Print Text", color: "white", textSize: 30, fontName: "Girassol-Regular", position: { x: 80, y: 30 } } }, | ||
{ operation: "overlay", overlay: OVERLAY, position: { x: 110, y: 25 } }, | ||
{ operation: "text", options: { text: "Test Print Text 2", color: "blue", textSize: 30, position: { x: 100, y: 80 }, thickness: 4 } }, | ||
{ operation: "text", options: { text: "Test Print Text 2", color: "brown", textSize: 30, position: { x: 100, y: 80 } } }, | ||
{ operation: "text", options: { text: "Test Print Text 3", color: "green", textSize: 30, position: { x: 180, y: 180 } } }, | ||
{ operation: "overlay", overlay: OVERLAY, position: { x: 15, y: 65 } }, | ||
{ operation: "text", options: { text: "Test Print Text 4", color: "orange", textSize: 30, position: { x: 30, y: 300 }, rotation: -40 } }, | ||
] | ||
{operation: 'flip', mode: FlipMode.Horizontal}, | ||
{operation: 'rotate', mode: RotationMode.R180}, | ||
{ | ||
operation: 'text', | ||
options: { | ||
text: 'Test Print Text', | ||
color: 'black', | ||
textSize: 30, | ||
fontName: 'Girassol-Regular', | ||
position: {x: 80, y: 30}, | ||
thickness: 4, | ||
}, | ||
}, | ||
{ | ||
operation: 'text', | ||
options: { | ||
text: 'Test Print Text', | ||
color: 'white', | ||
textSize: 30, | ||
fontName: 'Girassol-Regular', | ||
position: {x: 80, y: 30}, | ||
}, | ||
}, | ||
{operation: 'overlay', overlay: OVERLAY, position: {x: 110, y: 25}}, | ||
{ | ||
operation: 'text', | ||
options: { | ||
text: 'Test Print Text 2', | ||
color: 'blue', | ||
textSize: 30, | ||
position: {x: 100, y: 80}, | ||
thickness: 4, | ||
}, | ||
}, | ||
{ | ||
operation: 'text', | ||
options: { | ||
text: 'Test Print Text 2', | ||
color: 'brown', | ||
textSize: 30, | ||
position: {x: 100, y: 80}, | ||
}, | ||
}, | ||
{ | ||
operation: 'text', | ||
options: { | ||
text: 'Test Print Text 3', | ||
color: 'green', | ||
textSize: 30, | ||
position: {x: 180, y: 180}, | ||
}, | ||
}, | ||
{operation: 'overlay', overlay: OVERLAY, position: {x: 15, y: 65}}, | ||
{ | ||
operation: 'text', | ||
options: { | ||
text: 'Test Print Text 4', | ||
color: 'orange', | ||
textSize: 30, | ||
position: {x: 30, y: 300}, | ||
rotation: -40, | ||
}, | ||
}, | ||
]; | ||
} | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,73 @@ | ||
import * as React from "react" | ||
import { Image, Text } from "react-native" | ||
import styles, { ImageResultProps } from "../App.styles" | ||
import { noop } from "../utils" | ||
import PhotoManipulator from "react-native-photo-manipulator" | ||
import { IMAGE } from "./settings" | ||
import * as React from 'react'; | ||
import {Image, Text} from 'react-native'; | ||
import styles, {ImageResultProps} from '../App.styles'; | ||
import {noop} from '../utils'; | ||
import PhotoManipulator from 'react-native-photo-manipulator'; | ||
import {IMAGE} from './settings'; | ||
|
||
export default React.memo(function ExampleCrop() { | ||
const [crop, setCrop] = React.useState<string|null>(null); | ||
const [resize, setResize] = React.useState<string|null>(null); | ||
const [cropPng, setCropPng] = React.useState<string|null>(null); | ||
const [crop, setCrop] = React.useState<string | null>(null); | ||
const [resize, setResize] = React.useState<string | null>(null); | ||
const [cropPng, setCropPng] = React.useState<string | null>(null); | ||
|
||
React.useEffect(() => { | ||
const operation = async () => { | ||
setCrop(await PhotoManipulator.crop(IMAGE, { x: 400, y: 200, width: 300, height: 200 })); | ||
setResize(await PhotoManipulator.crop(IMAGE, { x: 400, y: 200, width: 300, height: 200 }, { width: 60, height: 40 })) | ||
setCropPng(await PhotoManipulator.crop(IMAGE, { x: 400, y: 200, width: 300, height: 200 })); | ||
setCrop( | ||
await PhotoManipulator.crop(IMAGE, { | ||
x: 400, | ||
y: 200, | ||
width: 300, | ||
height: 200, | ||
}), | ||
); | ||
setResize( | ||
await PhotoManipulator.crop( | ||
IMAGE, | ||
{x: 400, y: 200, width: 300, height: 200}, | ||
{width: 60, height: 40}, | ||
), | ||
); | ||
setCropPng( | ||
await PhotoManipulator.crop(IMAGE, { | ||
x: 400, | ||
y: 200, | ||
width: 300, | ||
height: 200, | ||
}), | ||
); | ||
}; | ||
|
||
operation().then(noop).catch(console.log); | ||
}, []); | ||
|
||
return ( | ||
<> | ||
{ typeof crop === "string" ? <Text style={styles.exampleDescription}>Crop</Text> : null } | ||
{ typeof crop === "string" ? <Image testID="cropResult" {...ImageResultProps} source={{ uri: crop}} /> : null } | ||
{ typeof resize === "string" ? <Text style={styles.exampleDescription}>Crop & Resize</Text> : null } | ||
{ typeof resize === "string" ? <Image testID="cropResizeResult" {...ImageResultProps} source={{ uri: resize}} /> : null } | ||
{ typeof cropPng === "string" ? <Text style={styles.exampleDescription}>PNG</Text> : null } | ||
{ typeof cropPng === "string" ? <Image testID="cropPngResult" {...ImageResultProps} source={{ uri: cropPng}} /> : null } | ||
{typeof crop === 'string' ? ( | ||
<Text style={styles.exampleDescription}>Crop</Text> | ||
) : null} | ||
{typeof crop === 'string' ? ( | ||
<Image testID="cropResult" {...ImageResultProps} source={{uri: crop}} /> | ||
) : null} | ||
{typeof resize === 'string' ? ( | ||
<Text style={styles.exampleDescription}>Crop & Resize</Text> | ||
) : null} | ||
{typeof resize === 'string' ? ( | ||
<Image | ||
testID="cropResizeResult" | ||
{...ImageResultProps} | ||
source={{uri: resize}} | ||
/> | ||
) : null} | ||
{typeof cropPng === 'string' ? ( | ||
<Text style={styles.exampleDescription}>PNG</Text> | ||
) : null} | ||
{typeof cropPng === 'string' ? ( | ||
<Image | ||
testID="cropPngResult" | ||
{...ImageResultProps} | ||
source={{uri: cropPng}} | ||
/> | ||
) : null} | ||
</> | ||
) | ||
}) | ||
); | ||
}); |
Oops, something went wrong.