@bigbinary/neetoui-rn 0.0.145 → 0.0.146
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/lib/components/Avatar.js +1 -1
- package/package.json +1 -1
- package/src/components/Avatar.js +38 -22
package/lib/components/Avatar.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.Avatar=void 0;var _extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends"));var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _objectWithoutProperties2=_interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));var _react=
|
|
1
|
+
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.Avatar=void 0;var _extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends"));var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _objectWithoutProperties2=_interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));var _react=_interopRequireDefault(require("react"));var _propTypes=_interopRequireDefault(require("prop-types"));var _reactNative=require("react-native");var _=require("./");var _reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated"));var _excluded=["name","variant","bgColor","fontColor","imageUrl"];var _this=this,_jsxFileName="/home/runner/work/neeto-ui-rn/neeto-ui-rn/src/components/Avatar.js";function _getRequireWildcardCache(nodeInterop){if(typeof WeakMap!=="function")return null;var cacheBabelInterop=new WeakMap();var cacheNodeInterop=new WeakMap();return(_getRequireWildcardCache=function _getRequireWildcardCache(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop;})(nodeInterop);}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule){return obj;}if(obj===null||typeof obj!=="object"&&typeof obj!=="function"){return{default:obj};}var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj)){return cache.get(obj);}var newObj={};var hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj){if(key!=="default"&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;if(desc&&(desc.get||desc.set)){Object.defineProperty(newObj,key,desc);}else{newObj[key]=obj[key];}}}newObj.default=obj;if(cache){cache.set(obj,newObj);}return newObj;}var Avatar=function Avatar(_ref){var name=_ref.name,_ref$variant=_ref.variant,variant=_ref$variant===void 0?"medium":_ref$variant,_ref$bgColor=_ref.bgColor,bgColor=_ref$bgColor===void 0?"background.lightBlue100":_ref$bgColor,_ref$fontColor=_ref.fontColor,fontColor=_ref$fontColor===void 0?"font.darkBlue100":_ref$fontColor,imageUrl=_ref.imageUrl,rest=(0,_objectWithoutProperties2.default)(_ref,_excluded);var opacity=(0,_reactNativeReanimated.useSharedValue)(0);var acronym=name==null?void 0:name.split(/\s/).reduce(function(response,word){return response+=word.slice(0,1);},"").slice(0,2);var getSizes=function getSizes(){switch(variant){case"small":return[36,12];case"medium":return[48,14];default:return[48,14];}};var _getSizes=getSizes(),_getSizes2=(0,_slicedToArray2.default)(_getSizes,2),avatarSize=_getSizes2[0],avatarFontSize=_getSizes2[1];var profileImageStyle=(0,_reactNativeReanimated.useAnimatedStyle)(function(){var _f=function _f(){return{opacity:(0,_reactNativeReanimated.withTiming)(opacity.value,{duration:300,easing:_reactNativeReanimated.Easing.bezier(0.25,0.1,0.25,1)}),height:avatarSize,width:avatarSize,alignSelf:"center",borderRadius:avatarSize/2};};_f._closure={withTiming:_reactNativeReanimated.withTiming,opacity:opacity,Easing:{bezier:_reactNativeReanimated.Easing.bezier},avatarSize:avatarSize};_f.asString="function _f(){const{withTiming,opacity,Easing,avatarSize}=jsThis._closure;{return{opacity:withTiming(opacity.value,{duration:300,easing:Easing.bezier(0.25,0.1,0.25,1)}),height:avatarSize,width:avatarSize,alignSelf:\"center\",borderRadius:avatarSize/2};}}";_f.__workletHash=7668075677523;_f.__location="/home/runner/work/neeto-ui-rn/neeto-ui-rn/src/components/Avatar.js (67:45)";_f.__optimalization=2;return _f;}());return _react.default.createElement(_react.default.Fragment,null,_react.default.createElement(_.Container,(0,_extends2.default)({bg:bgColor,width:avatarSize,height:avatarSize,borderRadius:avatarSize/2},rest,{flexDirection:"row",__self:_this,__source:{fileName:_jsxFileName,lineNumber:82,columnNumber:7}}),_react.default.createElement(_.Container,{style:styles.acronym,__self:_this,__source:{fileName:_jsxFileName,lineNumber:90,columnNumber:9}},_react.default.createElement(_.Typography,{fontFamily:"sf400",fontSize:avatarFontSize,color:fontColor,__self:_this,__source:{fileName:_jsxFileName,lineNumber:91,columnNumber:11}},acronym.toUpperCase())),_react.default.createElement(_reactNativeReanimated.default.Image,(0,_extends2.default)({onLoad:function onLoad(){return opacity.value=1;},style:profileImageStyle,source:{uri:imageUrl}},rest,{__self:_this,__source:{fileName:_jsxFileName,lineNumber:99,columnNumber:9}}))));};exports.Avatar=Avatar;var styles=_reactNative.StyleSheet.create({acronym:{position:"absolute",justifyContent:"center",alignItems:"center"}});Avatar.defaultProps={alignItems:"center",justifyContent:"center"};Avatar.propTypes={name:_propTypes.default.string,variant:_propTypes.default.oneOf(["medium","small"]),bgColor:_propTypes.default.string,fontColor:_propTypes.default.string,imageUrl:_propTypes.default.string};
|
package/package.json
CHANGED
package/src/components/Avatar.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from "react";
|
|
2
2
|
import PropTypes from "prop-types";
|
|
3
|
-
import {
|
|
3
|
+
import { StyleSheet } from "react-native";
|
|
4
4
|
|
|
5
5
|
import { Typography, Container } from "@components";
|
|
6
|
+
import Animated, {
|
|
7
|
+
Easing,
|
|
8
|
+
useAnimatedStyle,
|
|
9
|
+
useSharedValue,
|
|
10
|
+
withTiming,
|
|
11
|
+
} from "react-native-reanimated";
|
|
6
12
|
|
|
7
13
|
/**
|
|
8
14
|
* Avatars can be used to represent people in a graphical way.
|
|
@@ -39,7 +45,7 @@ export const Avatar = ({
|
|
|
39
45
|
imageUrl,
|
|
40
46
|
...rest
|
|
41
47
|
}) => {
|
|
42
|
-
const
|
|
48
|
+
const opacity = useSharedValue(0);
|
|
43
49
|
const acronym = name
|
|
44
50
|
?.split(/\s/)
|
|
45
51
|
.reduce((response, word) => (response += word.slice(0, 1)), "")
|
|
@@ -58,27 +64,30 @@ export const Avatar = ({
|
|
|
58
64
|
|
|
59
65
|
const [avatarSize, avatarFontSize] = getSizes();
|
|
60
66
|
|
|
61
|
-
const
|
|
62
|
-
|
|
67
|
+
const profileImageStyle = useAnimatedStyle(() => {
|
|
68
|
+
return {
|
|
69
|
+
opacity: withTiming(opacity.value, {
|
|
70
|
+
duration: 300,
|
|
71
|
+
easing: Easing.bezier(0.25, 0.1, 0.25, 1),
|
|
72
|
+
}),
|
|
63
73
|
height: avatarSize,
|
|
64
74
|
width: avatarSize,
|
|
65
75
|
alignSelf: "center",
|
|
66
76
|
borderRadius: avatarSize / 2,
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const renderFallbackText = fallback || !imageUrl;
|
|
77
|
+
};
|
|
78
|
+
});
|
|
71
79
|
|
|
72
80
|
return (
|
|
73
81
|
<>
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
<Container
|
|
83
|
+
bg={bgColor}
|
|
84
|
+
width={avatarSize}
|
|
85
|
+
height={avatarSize}
|
|
86
|
+
borderRadius={avatarSize / 2}
|
|
87
|
+
{...rest}
|
|
88
|
+
flexDirection="row"
|
|
89
|
+
>
|
|
90
|
+
<Container style={styles.acronym}>
|
|
82
91
|
<Typography
|
|
83
92
|
fontFamily="sf400"
|
|
84
93
|
fontSize={avatarFontSize}
|
|
@@ -87,18 +96,25 @@ export const Avatar = ({
|
|
|
87
96
|
{acronym.toUpperCase()}
|
|
88
97
|
</Typography>
|
|
89
98
|
</Container>
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
style={
|
|
99
|
+
<Animated.Image
|
|
100
|
+
onLoad={() => (opacity.value = 1)}
|
|
101
|
+
style={profileImageStyle}
|
|
93
102
|
source={{ uri: imageUrl }}
|
|
94
|
-
onError={() => setFallback(true)}
|
|
95
103
|
{...rest}
|
|
96
104
|
/>
|
|
97
|
-
|
|
105
|
+
</Container>
|
|
98
106
|
</>
|
|
99
107
|
);
|
|
100
108
|
};
|
|
101
109
|
|
|
110
|
+
const styles = StyleSheet.create({
|
|
111
|
+
acronym: {
|
|
112
|
+
position: "absolute",
|
|
113
|
+
justifyContent: "center",
|
|
114
|
+
alignItems: "center",
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
|
|
102
118
|
Avatar.defaultProps = {
|
|
103
119
|
alignItems: "center",
|
|
104
120
|
justifyContent: "center",
|