|
@@ -74,8 +74,9 @@ export default class Avatar extends Component {
|
74
|
74
|
// uri
|
75
|
75
|
const prevURI = this.props && this.props.uri;
|
76
|
76
|
const nextURI = nextProps && nextProps.uri;
|
|
77
|
+ const assignState = !this.state;
|
77
|
78
|
|
78
|
|
- if (prevURI !== nextURI || !this.state) {
|
|
79
|
+ if (prevURI !== nextURI || assignState) {
|
79
|
80
|
const nextState = {
|
80
|
81
|
backgroundColor: this._getBackgroundColor(nextProps),
|
81
|
82
|
|
|
@@ -92,10 +93,10 @@ export default class Avatar extends Component {
|
92
|
93
|
source: _DEFAULT_SOURCE
|
93
|
94
|
};
|
94
|
95
|
|
95
|
|
- if (this.state) {
|
96
|
|
- this.setState(nextState);
|
97
|
|
- } else {
|
|
96
|
+ if (assignState) {
|
98
|
97
|
this.state = nextState;
|
|
98
|
+ } else {
|
|
99
|
+ this.setState(nextState);
|
99
|
100
|
}
|
100
|
101
|
|
101
|
102
|
// XXX @lyubomir: My logic for the character # bellow is as follows:
|
|
@@ -113,22 +114,32 @@ export default class Avatar extends Component {
|
113
|
114
|
// an image retrieval action.
|
114
|
115
|
if (nextURI && !nextURI.startsWith('#')) {
|
115
|
116
|
const nextSource = { uri: nextURI };
|
|
117
|
+ const observer = () => {
|
|
118
|
+ this._unmounted || this.setState((prevState, props) => {
|
|
119
|
+ if (props.uri === nextURI
|
|
120
|
+ && (!prevState.source
|
|
121
|
+ || prevState.source.uri !== nextURI)) {
|
|
122
|
+ return { source: nextSource };
|
|
123
|
+ }
|
|
124
|
+
|
|
125
|
+ return {};
|
|
126
|
+ });
|
|
127
|
+ };
|
116
|
128
|
|
117
|
129
|
// Wait for the source/URI to load.
|
118
|
|
- ImageCache.get().on(
|
119
|
|
- nextSource,
|
120
|
|
- /* observer */ () => {
|
121
|
|
- this._unmounted || this.setState((prevState, props) => {
|
122
|
|
- if (props.uri === nextURI
|
123
|
|
- && (!prevState.source
|
124
|
|
- || prevState.source.uri !== nextURI)) {
|
125
|
|
- return { source: nextSource };
|
126
|
|
- }
|
127
|
|
-
|
128
|
|
- return {};
|
129
|
|
- });
|
130
|
|
- },
|
131
|
|
- /* immutable */ true);
|
|
130
|
+ if (ImageCache) {
|
|
131
|
+ ImageCache.get().on(
|
|
132
|
+ nextSource,
|
|
133
|
+ observer,
|
|
134
|
+ /* immutable */ true);
|
|
135
|
+ } else if (assignState) {
|
|
136
|
+ this.state = {
|
|
137
|
+ ...this.state,
|
|
138
|
+ source: nextSource
|
|
139
|
+ };
|
|
140
|
+ } else {
|
|
141
|
+ observer();
|
|
142
|
+ }
|
132
|
143
|
}
|
133
|
144
|
}
|
134
|
145
|
}
|