@arturhoncharuk/react-native-jazzicon 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +52 -0
- package/lib/module/constants/index.js +25 -0
- package/lib/module/constants/index.js.map +1 -0
- package/lib/module/index.js +87 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types/index.js +4 -0
- package/lib/module/types/index.js.map +1 -0
- package/lib/module/utils/index.js +2 -0
- package/lib/module/utils/index.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/constants/index.d.ts +4 -0
- package/lib/typescript/src/constants/index.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +11 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/types/index.d.ts +13 -0
- package/lib/typescript/src/types/index.d.ts.map +1 -0
- package/lib/typescript/src/utils/index.d.ts +1 -0
- package/lib/typescript/src/utils/index.d.ts.map +1 -0
- package/package.json +170 -0
- package/src/constants/index.ts +15 -0
- package/src/index.tsx +113 -0
- package/src/types/index.ts +14 -0
- package/src/utils/index.ts +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ArturHoncharuk
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# react-native-jazzicon
|
|
2
|
+
|
|
3
|
+
React Native library for generating deterministic Jazzicons (Ethereum-style identicons) from addresses.
|
|
4
|
+
|
|
5
|
+
<img src="./example.png" alt="react-native-jazzicon example" width="420" />
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install react-native-jazzicon
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { Jazzicon } from 'react-native-jazzicon';
|
|
17
|
+
|
|
18
|
+
const ADDRESSES = [
|
|
19
|
+
'0x1234567890123456789012345678901234567890',
|
|
20
|
+
'0x742d35Cc6634C0532925a3b844Bc9e7595f2EE31',
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
function Example() {
|
|
24
|
+
return (
|
|
25
|
+
<>
|
|
26
|
+
<Jazzicon size={80} address={ADDRESSES[0]} />
|
|
27
|
+
<Jazzicon size={40} address={ADDRESSES[1]} />
|
|
28
|
+
</>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Props
|
|
34
|
+
|
|
35
|
+
- **`size`**: number – diameter of the identicon in pixels. Defaults to `16`.
|
|
36
|
+
- **`address`**: string – wallet address used to generate the identicon. If provided, it is converted to a deterministic seed.
|
|
37
|
+
- **`seed`**: number (optional) – numeric seed used when `address` is not passed.
|
|
38
|
+
- **`containerStyle`**: `ViewStyle` (optional) – additional styles for the outer container.
|
|
39
|
+
|
|
40
|
+
## Contributing
|
|
41
|
+
|
|
42
|
+
- [Development workflow](CONTRIBUTING.md#development-workflow)
|
|
43
|
+
- [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request)
|
|
44
|
+
- [Code of conduct](CODE_OF_CONDUCT.md)
|
|
45
|
+
|
|
46
|
+
## License
|
|
47
|
+
|
|
48
|
+
MIT
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
export const COLORS = ['#01888C',
|
|
4
|
+
// teal
|
|
5
|
+
'#FC7500',
|
|
6
|
+
// bright orange
|
|
7
|
+
'#034F5D',
|
|
8
|
+
// dark teal
|
|
9
|
+
'#F73F01',
|
|
10
|
+
// orangered
|
|
11
|
+
'#FC1960',
|
|
12
|
+
// magenta
|
|
13
|
+
'#C7144C',
|
|
14
|
+
// raspberry
|
|
15
|
+
'#F3C100',
|
|
16
|
+
// goldenrod
|
|
17
|
+
'#1598F2',
|
|
18
|
+
// lightning blue
|
|
19
|
+
'#2465E1',
|
|
20
|
+
// sail blue
|
|
21
|
+
'#F19E02' // gold
|
|
22
|
+
];
|
|
23
|
+
export const wobble = 30;
|
|
24
|
+
export const shapeCount = 3;
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["COLORS","wobble","shapeCount"],"sourceRoot":"../../../src","sources":["constants/index.ts"],"mappings":";;AAAA,OAAO,MAAMA,MAAM,GAAG,CACpB,SAAS;AAAE;AACX,SAAS;AAAE;AACX,SAAS;AAAE;AACX,SAAS;AAAE;AACX,SAAS;AAAE;AACX,SAAS;AAAE;AACX,SAAS;AAAE;AACX,SAAS;AAAE;AACX,SAAS;AAAE;AACX,SAAS,CAAE;AAAA,CACZ;AAED,OAAO,MAAMC,MAAM,GAAG,EAAE;AACxB,OAAO,MAAMC,UAAU,GAAG,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { Component } from 'react';
|
|
4
|
+
import { StyleSheet, View } from 'react-native';
|
|
5
|
+
import { Svg, Rect } from 'react-native-svg';
|
|
6
|
+
import MersenneTwister from 'mersenne-twister';
|
|
7
|
+
import Color from 'color';
|
|
8
|
+
import { COLORS, wobble, shapeCount } from "./constants/index.js";
|
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
+
export class Jazzicon extends Component {
|
|
11
|
+
static propsToState({
|
|
12
|
+
seed,
|
|
13
|
+
address
|
|
14
|
+
}) {
|
|
15
|
+
if (address) {
|
|
16
|
+
address = address.toLowerCase();
|
|
17
|
+
if (address.startsWith('0x')) {
|
|
18
|
+
seed = parseInt(address.slice(2, 10), 16);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const generator = new MersenneTwister(seed);
|
|
22
|
+
const amount = generator.random() * 30 - wobble / 2;
|
|
23
|
+
return {
|
|
24
|
+
generator,
|
|
25
|
+
colors: COLORS.map(hex => new Color(hex).rotate(amount).hex())
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
state = Jazzicon.propsToState(this.props);
|
|
29
|
+
static getDerivedStateFromProps(props, _state) {
|
|
30
|
+
return Jazzicon.propsToState(props);
|
|
31
|
+
}
|
|
32
|
+
render() {
|
|
33
|
+
const {
|
|
34
|
+
containerStyle,
|
|
35
|
+
size = 16
|
|
36
|
+
} = this.props;
|
|
37
|
+
return /*#__PURE__*/_jsx(View, {
|
|
38
|
+
style: [styles.container, {
|
|
39
|
+
width: size,
|
|
40
|
+
height: size,
|
|
41
|
+
backgroundColor: this.randomColor,
|
|
42
|
+
borderRadius: size / 2
|
|
43
|
+
}, containerStyle],
|
|
44
|
+
children: /*#__PURE__*/_jsx(Svg, {
|
|
45
|
+
width: size,
|
|
46
|
+
height: size,
|
|
47
|
+
children: Array(shapeCount).fill(0).map((_, index) => {
|
|
48
|
+
const center = size / 2;
|
|
49
|
+
const firstRot = this.randomNumber;
|
|
50
|
+
const angle = Math.PI * 2 * firstRot;
|
|
51
|
+
const velocity = size / shapeCount * this.randomNumber + index * size / shapeCount;
|
|
52
|
+
const tx = Math.cos(angle) * velocity;
|
|
53
|
+
const ty = Math.sin(angle) * velocity;
|
|
54
|
+
const secondRot = this.randomNumber;
|
|
55
|
+
const rot = firstRot * 360 + secondRot * 180;
|
|
56
|
+
return /*#__PURE__*/_jsx(Rect, {
|
|
57
|
+
x: 0,
|
|
58
|
+
y: 0,
|
|
59
|
+
width: size,
|
|
60
|
+
height: size,
|
|
61
|
+
fill: this.randomColor,
|
|
62
|
+
transform: `translate(${tx} ${ty}) rotate(${rot.toFixed(1)} ${center} ${center})`
|
|
63
|
+
}, `shape_${index}`);
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
get randomNumber() {
|
|
69
|
+
const {
|
|
70
|
+
generator
|
|
71
|
+
} = this.state;
|
|
72
|
+
return generator.random();
|
|
73
|
+
}
|
|
74
|
+
get randomColor() {
|
|
75
|
+
const {
|
|
76
|
+
colors
|
|
77
|
+
} = this.state;
|
|
78
|
+
this.randomNumber;
|
|
79
|
+
return colors.splice(Math.floor(colors.length * this.randomNumber), 1)[0] ?? '#000000';
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const styles = StyleSheet.create({
|
|
83
|
+
container: {
|
|
84
|
+
overflow: 'hidden'
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Component","StyleSheet","View","Svg","Rect","MersenneTwister","Color","COLORS","wobble","shapeCount","jsx","_jsx","Jazzicon","propsToState","seed","address","toLowerCase","startsWith","parseInt","slice","generator","amount","random","colors","map","hex","rotate","state","props","getDerivedStateFromProps","_state","render","containerStyle","size","style","styles","container","width","height","backgroundColor","randomColor","borderRadius","children","Array","fill","_","index","center","firstRot","randomNumber","angle","Math","PI","velocity","tx","cos","ty","sin","secondRot","rot","x","y","transform","toFixed","splice","floor","length","create","overflow"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,SAAS,QAAQ,OAAO;AACjC,SAASC,UAAU,EAAEC,IAAI,QAAQ,cAAc;AAC/C,SAASC,GAAG,EAAEC,IAAI,QAAQ,kBAAkB;AAC5C,OAAOC,eAAe,MAAM,kBAAkB;AAC9C,OAAOC,KAAK,MAAM,OAAO;AAEzB,SAASC,MAAM,EAAEC,MAAM,EAAEC,UAAU,QAAQ,sBAAa;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAEzD,OAAO,MAAMC,QAAQ,SAASZ,SAAS,CAAiC;EACtE,OAAea,YAAYA,CAAC;IAC1BC,IAAI;IACJC;EACc,CAAC,EAAkB;IACjC,IAAIA,OAAO,EAAE;MACXA,OAAO,GAAGA,OAAO,CAACC,WAAW,CAAC,CAAC;MAE/B,IAAID,OAAO,CAACE,UAAU,CAAC,IAAI,CAAC,EAAE;QAC5BH,IAAI,GAAGI,QAAQ,CAACH,OAAO,CAACI,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;MAC3C;IACF;IAEA,MAAMC,SAAS,GAAG,IAAIf,eAAe,CAACS,IAAI,CAAC;IAC3C,MAAMO,MAAM,GAAGD,SAAS,CAACE,MAAM,CAAC,CAAC,GAAG,EAAE,GAAGd,MAAM,GAAG,CAAC;IACnD,OAAO;MACLY,SAAS;MACTG,MAAM,EAAEhB,MAAM,CAACiB,GAAG,CAAEC,GAAG,I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],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["utils/index.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/constants/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM,UAWlB,CAAC;AAEF,eAAO,MAAM,MAAM,KAAK,CAAC;AACzB,eAAO,MAAM,UAAU,IAAI,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Component } from 'react';
|
|
2
|
+
import type { TJazziconProps, TJazziconState } from './types';
|
|
3
|
+
export declare class Jazzicon extends Component<TJazziconProps, TJazziconState> {
|
|
4
|
+
private static propsToState;
|
|
5
|
+
state: TJazziconState;
|
|
6
|
+
static getDerivedStateFromProps(props: TJazziconProps, _state: TJazziconState): Partial<TJazziconState> | null;
|
|
7
|
+
render(): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
private get randomNumber();
|
|
9
|
+
private get randomColor();
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAKlC,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAG9D,qBAAa,QAAS,SAAQ,SAAS,CAAC,cAAc,EAAE,cAAc,CAAC;IACrE,OAAO,CAAC,MAAM,CAAC,YAAY;IAoBpB,KAAK,EAAE,cAAc,CAAqC;WAEnD,wBAAwB,CACpC,KAAK,EAAE,cAAc,EACrB,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC,cAAc,CAAC,GAAG,IAAI;IAI1B,MAAM;IAqDb,OAAO,KAAK,YAAY,GAGvB;IAED,OAAO,KAAK,WAAW,GAStB;CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { StyleProp, ViewStyle } from 'react-native';
|
|
2
|
+
import type * as MersenneTwister from 'mersenne-twister';
|
|
3
|
+
export type TJazziconProps = {
|
|
4
|
+
size?: number;
|
|
5
|
+
address?: string;
|
|
6
|
+
seed?: number;
|
|
7
|
+
containerStyle?: StyleProp<ViewStyle>;
|
|
8
|
+
};
|
|
9
|
+
export type TJazziconState = {
|
|
10
|
+
generator: MersenneTwister.IMersenneTwister;
|
|
11
|
+
colors: string[];
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,KAAK,KAAK,eAAe,MAAM,kBAAkB,CAAC;AAEzD,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;CACvC,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,SAAS,EAAE,eAAe,CAAC,gBAAgB,CAAC;IAC5C,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/utils/index.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@arturhoncharuk/react-native-jazzicon",
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"description": "React Native library for generating deterministic Jazzicons (Ethereum-style identicons) from addresses.",
|
|
5
|
+
"main": "./lib/module/index.js",
|
|
6
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"source": "./src/index.tsx",
|
|
10
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
11
|
+
"default": "./lib/module/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"src",
|
|
17
|
+
"lib",
|
|
18
|
+
"android",
|
|
19
|
+
"ios",
|
|
20
|
+
"cpp",
|
|
21
|
+
"*.podspec",
|
|
22
|
+
"react-native.config.js",
|
|
23
|
+
"!ios/build",
|
|
24
|
+
"!android/build",
|
|
25
|
+
"!android/gradle",
|
|
26
|
+
"!android/gradlew",
|
|
27
|
+
"!android/gradlew.bat",
|
|
28
|
+
"!android/local.properties",
|
|
29
|
+
"!**/__tests__",
|
|
30
|
+
"!**/__fixtures__",
|
|
31
|
+
"!**/__mocks__",
|
|
32
|
+
"!**/.*"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"example": "yarn workspace react-native-jazzicon-example",
|
|
36
|
+
"clean": "del-cli lib",
|
|
37
|
+
"prepare": "bob build",
|
|
38
|
+
"typecheck": "tsc",
|
|
39
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
40
|
+
"test": "jest",
|
|
41
|
+
"release": "release-it --only-version"
|
|
42
|
+
},
|
|
43
|
+
"keywords": [
|
|
44
|
+
"react-native",
|
|
45
|
+
"ios",
|
|
46
|
+
"android"
|
|
47
|
+
],
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "git+https://github.com/ArturHoncharuk/react-native-jazzicon"
|
|
51
|
+
},
|
|
52
|
+
"author": "ArturHoncharuk <dotwork.play@gmail.com> (https://github.com/ArturHoncharuk)",
|
|
53
|
+
"license": "MIT",
|
|
54
|
+
"bugs": {
|
|
55
|
+
"url": "https://github.com/ArturHoncharuk/react-native-jazzicon/issues"
|
|
56
|
+
},
|
|
57
|
+
"homepage": "https://github.com/ArturHoncharuk/react-native-jazzicon#readme",
|
|
58
|
+
"publishConfig": {
|
|
59
|
+
"registry": "https://registry.npmjs.org/"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@commitlint/config-conventional": "^19.8.1",
|
|
63
|
+
"@eslint/compat": "^1.3.2",
|
|
64
|
+
"@eslint/eslintrc": "^3.3.1",
|
|
65
|
+
"@eslint/js": "^9.35.0",
|
|
66
|
+
"@react-native/babel-preset": "0.83.0",
|
|
67
|
+
"@react-native/eslint-config": "0.83.0",
|
|
68
|
+
"@release-it/conventional-changelog": "^10.0.1",
|
|
69
|
+
"@types/jest": "^29.5.14",
|
|
70
|
+
"@types/mersenne-twister": "^1.1.7",
|
|
71
|
+
"@types/react": "^19.1.12",
|
|
72
|
+
"commitlint": "^19.8.1",
|
|
73
|
+
"del-cli": "^6.0.0",
|
|
74
|
+
"eslint": "^9.35.0",
|
|
75
|
+
"eslint-config-prettier": "^10.1.8",
|
|
76
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
77
|
+
"jest": "^29.7.0",
|
|
78
|
+
"lefthook": "^2.0.3",
|
|
79
|
+
"prettier": "^2.8.8",
|
|
80
|
+
"react": "19.2.0",
|
|
81
|
+
"react-native": "0.83.2",
|
|
82
|
+
"react-native-builder-bob": "^0.40.13",
|
|
83
|
+
"release-it": "^19.0.4",
|
|
84
|
+
"turbo": "^2.5.6",
|
|
85
|
+
"typescript": "^5.9.2"
|
|
86
|
+
},
|
|
87
|
+
"peerDependencies": {
|
|
88
|
+
"react": "*",
|
|
89
|
+
"react-native": "*"
|
|
90
|
+
},
|
|
91
|
+
"workspaces": [
|
|
92
|
+
"example"
|
|
93
|
+
],
|
|
94
|
+
"packageManager": "yarn@4.11.0",
|
|
95
|
+
"react-native-builder-bob": {
|
|
96
|
+
"source": "src",
|
|
97
|
+
"output": "lib",
|
|
98
|
+
"targets": [
|
|
99
|
+
[
|
|
100
|
+
"module",
|
|
101
|
+
{
|
|
102
|
+
"esm": true
|
|
103
|
+
}
|
|
104
|
+
],
|
|
105
|
+
[
|
|
106
|
+
"typescript",
|
|
107
|
+
{
|
|
108
|
+
"project": "tsconfig.build.json"
|
|
109
|
+
}
|
|
110
|
+
]
|
|
111
|
+
]
|
|
112
|
+
},
|
|
113
|
+
"prettier": {
|
|
114
|
+
"quoteProps": "consistent",
|
|
115
|
+
"singleQuote": true,
|
|
116
|
+
"tabWidth": 2,
|
|
117
|
+
"trailingComma": "es5",
|
|
118
|
+
"useTabs": false
|
|
119
|
+
},
|
|
120
|
+
"jest": {
|
|
121
|
+
"preset": "react-native",
|
|
122
|
+
"modulePathIgnorePatterns": [
|
|
123
|
+
"<rootDir>/example/node_modules",
|
|
124
|
+
"<rootDir>/lib/"
|
|
125
|
+
],
|
|
126
|
+
"transformIgnorePatterns": [
|
|
127
|
+
"node_modules/(?!((jest-)?react-native|@react-native(-community)?|color|color-name|color-string|color-convert|mersenne-twister|react-native-svg)/)"
|
|
128
|
+
]
|
|
129
|
+
},
|
|
130
|
+
"commitlint": {
|
|
131
|
+
"extends": [
|
|
132
|
+
"@commitlint/config-conventional"
|
|
133
|
+
]
|
|
134
|
+
},
|
|
135
|
+
"release-it": {
|
|
136
|
+
"git": {
|
|
137
|
+
"commitMessage": "chore: release ${version}",
|
|
138
|
+
"tagName": "v${version}"
|
|
139
|
+
},
|
|
140
|
+
"npm": {
|
|
141
|
+
"publish": true
|
|
142
|
+
},
|
|
143
|
+
"github": {
|
|
144
|
+
"release": true
|
|
145
|
+
},
|
|
146
|
+
"plugins": {
|
|
147
|
+
"@release-it/conventional-changelog": {
|
|
148
|
+
"preset": {
|
|
149
|
+
"name": "angular"
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
"create-react-native-library": {
|
|
155
|
+
"type": "library",
|
|
156
|
+
"languages": "js",
|
|
157
|
+
"tools": [
|
|
158
|
+
"eslint",
|
|
159
|
+
"jest",
|
|
160
|
+
"lefthook",
|
|
161
|
+
"release-it"
|
|
162
|
+
],
|
|
163
|
+
"version": "0.57.2"
|
|
164
|
+
},
|
|
165
|
+
"dependencies": {
|
|
166
|
+
"color": "^5.0.3",
|
|
167
|
+
"mersenne-twister": "^1.1.0",
|
|
168
|
+
"react-native-svg": "^15.15.3"
|
|
169
|
+
}
|
|
170
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const COLORS = [
|
|
2
|
+
'#01888C', // teal
|
|
3
|
+
'#FC7500', // bright orange
|
|
4
|
+
'#034F5D', // dark teal
|
|
5
|
+
'#F73F01', // orangered
|
|
6
|
+
'#FC1960', // magenta
|
|
7
|
+
'#C7144C', // raspberry
|
|
8
|
+
'#F3C100', // goldenrod
|
|
9
|
+
'#1598F2', // lightning blue
|
|
10
|
+
'#2465E1', // sail blue
|
|
11
|
+
'#F19E02', // gold
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
export const wobble = 30;
|
|
15
|
+
export const shapeCount = 3;
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { Component } from 'react';
|
|
2
|
+
import { StyleSheet, View } from 'react-native';
|
|
3
|
+
import { Svg, Rect } from 'react-native-svg';
|
|
4
|
+
import MersenneTwister from 'mersenne-twister';
|
|
5
|
+
import Color from 'color';
|
|
6
|
+
import type { TJazziconProps, TJazziconState } from './types';
|
|
7
|
+
import { COLORS, wobble, shapeCount } from './constants';
|
|
8
|
+
|
|
9
|
+
export class Jazzicon extends Component<TJazziconProps, TJazziconState> {
|
|
10
|
+
private static propsToState({
|
|
11
|
+
seed,
|
|
12
|
+
address,
|
|
13
|
+
}: TJazziconProps): TJazziconState {
|
|
14
|
+
if (address) {
|
|
15
|
+
address = address.toLowerCase();
|
|
16
|
+
|
|
17
|
+
if (address.startsWith('0x')) {
|
|
18
|
+
seed = parseInt(address.slice(2, 10), 16);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const generator = new MersenneTwister(seed);
|
|
23
|
+
const amount = generator.random() * 30 - wobble / 2;
|
|
24
|
+
return {
|
|
25
|
+
generator,
|
|
26
|
+
colors: COLORS.map((hex) => new Color(hex).rotate(amount).hex()),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public state: TJazziconState = Jazzicon.propsToState(this.props);
|
|
31
|
+
|
|
32
|
+
public static getDerivedStateFromProps(
|
|
33
|
+
props: TJazziconProps,
|
|
34
|
+
_state: TJazziconState
|
|
35
|
+
): Partial<TJazziconState> | null {
|
|
36
|
+
return Jazzicon.propsToState(props);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public render() {
|
|
40
|
+
const { containerStyle, size = 16 } = this.props;
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<View
|
|
44
|
+
style={[
|
|
45
|
+
styles.container,
|
|
46
|
+
{
|
|
47
|
+
width: size,
|
|
48
|
+
height: size,
|
|
49
|
+
backgroundColor: this.randomColor,
|
|
50
|
+
borderRadius: size / 2,
|
|
51
|
+
},
|
|
52
|
+
containerStyle,
|
|
53
|
+
]}
|
|
54
|
+
>
|
|
55
|
+
<Svg width={size} height={size}>
|
|
56
|
+
{Array(shapeCount)
|
|
57
|
+
.fill(0)
|
|
58
|
+
.map((_, index) => {
|
|
59
|
+
const center = size / 2;
|
|
60
|
+
|
|
61
|
+
const firstRot = this.randomNumber;
|
|
62
|
+
const angle = Math.PI * 2 * firstRot;
|
|
63
|
+
const velocity =
|
|
64
|
+
(size / shapeCount) * this.randomNumber +
|
|
65
|
+
(index * size) / shapeCount;
|
|
66
|
+
|
|
67
|
+
const tx = Math.cos(angle) * velocity;
|
|
68
|
+
const ty = Math.sin(angle) * velocity;
|
|
69
|
+
|
|
70
|
+
const secondRot = this.randomNumber;
|
|
71
|
+
const rot = firstRot * 360 + secondRot * 180;
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<Rect
|
|
75
|
+
key={`shape_${index}`}
|
|
76
|
+
x={0}
|
|
77
|
+
y={0}
|
|
78
|
+
width={size}
|
|
79
|
+
height={size}
|
|
80
|
+
fill={this.randomColor}
|
|
81
|
+
transform={`translate(${tx} ${ty}) rotate(${rot.toFixed(
|
|
82
|
+
1
|
|
83
|
+
)} ${center} ${center})`}
|
|
84
|
+
/>
|
|
85
|
+
);
|
|
86
|
+
})}
|
|
87
|
+
</Svg>
|
|
88
|
+
</View>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private get randomNumber(): number {
|
|
93
|
+
const { generator } = this.state;
|
|
94
|
+
return generator.random();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private get randomColor(): string {
|
|
98
|
+
const { colors } = this.state;
|
|
99
|
+
|
|
100
|
+
this.randomNumber;
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
colors.splice(Math.floor(colors.length * this.randomNumber), 1)[0] ??
|
|
104
|
+
'#000000'
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const styles = StyleSheet.create({
|
|
110
|
+
container: {
|
|
111
|
+
overflow: 'hidden',
|
|
112
|
+
},
|
|
113
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { StyleProp, ViewStyle } from 'react-native';
|
|
2
|
+
import type * as MersenneTwister from 'mersenne-twister';
|
|
3
|
+
|
|
4
|
+
export type TJazziconProps = {
|
|
5
|
+
size?: number;
|
|
6
|
+
address?: string;
|
|
7
|
+
seed?: number;
|
|
8
|
+
containerStyle?: StyleProp<ViewStyle>;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type TJazziconState = {
|
|
12
|
+
generator: MersenneTwister.IMersenneTwister;
|
|
13
|
+
colors: string[];
|
|
14
|
+
};
|
|
File without changes
|