Skip to content

Commit d9acc61

Browse files
committed
fix: getter fix
1 parent e59783e commit d9acc61

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/index.common.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,25 @@ function createGetter(key: string, options: NativePropertyOptions) {
1212
const converter = options.converter;
1313
return function () {
1414
let result;
15+
if (this['_' + key]) {
16+
return this['_' + key];
17+
}
1518
if (this.native && this.native[nativeGetterName]) {
1619
result = this.native[nativeGetterName]();
20+
result = converter ? converter.fromNative.call(this, result, key) : result;
1721
} else {
1822
result = this.options[key] || options.defaultValue;
1923
}
20-
result = converter ? converter.fromNative.call(this, result, key) : result;
2124
return result;
2225
};
2326
}
2427
function createSetter(key, options: NativePropertyOptions) {
2528
const nativeSetterName = ((isAndroid ? options.android : options.ios) || options).nativeSetterName || 'set' + key.charAt(0).toUpperCase() + key.slice(1);
2629
return function (newVal) {
27-
this.options[key] = newVal;
30+
if (this['_' + key] === newVal) {
31+
return;
32+
}
33+
this['_' + key] = this.options[key] = newVal;
2834
if (this.native && this.native[nativeSetterName]) {
2935
const actualVal = options.converter ? options.converter.toNative.call(this, newVal, key) : newVal;
3036
this.native[nativeSetterName](actualVal);

0 commit comments

Comments
 (0)