Skip to content

Commit 1cd25e6

Browse files
authored
Fix color processing on iOS (#7250)
1 parent 8b4d033 commit 1cd25e6

File tree

2 files changed

+56
-29
lines changed

2 files changed

+56
-29
lines changed

lib/src/commands/OptionsProcessor.test.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,8 @@ describe('navigation options', () => {
537537

538538
uut.processOptions(options, CommandName.SetRoot);
539539
expect(options).toEqual({
540-
statusBar: { backgroundColor: { dynamic: { light: 0xffff0000, dark: 0xffff0000 } } },
541-
topBar: { background: { color: { dynamic: { light: 0xff0000ff, dark: 0xff0000ff } } } },
540+
statusBar: { backgroundColor: 0xffff0000 },
541+
topBar: { background: { color: 0xff0000ff } },
542542
});
543543
});
544544

@@ -549,7 +549,7 @@ describe('navigation options', () => {
549549

550550
uut.processOptions(options, CommandName.SetRoot);
551551
expect(options).toEqual({
552-
topBar: { background: { color: { dynamic: { light: 'NoColor', dark: 'NoColor' } } } },
552+
topBar: { background: { color: 'NoColor' } },
553553
});
554554
});
555555

@@ -565,11 +565,11 @@ describe('navigation options', () => {
565565
};
566566
uut.processOptions(options, CommandName.SetRoot);
567567
expect(options).toEqual({
568-
statusBar: { backgroundColor: { dynamic: { light: 0xffff0000, dark: 0xffff0000 } } },
568+
statusBar: { backgroundColor: 0xffff0000 },
569569
topBar: {
570570
background: { color: { dynamic: { light: 0xff0000ff, dark: 0xffff0000 } } },
571571
title: {
572-
color: { dynamic: { light: null, dark: null } },
572+
color: undefined,
573573
},
574574
},
575575
});
@@ -585,6 +585,17 @@ describe('navigation options', () => {
585585
topBar: { background: { color: { dynamic: { light: 0xffff0000, dark: 0xff0000ff } } } },
586586
});
587587
});
588+
589+
it('should not process undefined value', () => {
590+
const options: Options = {
591+
topBar: { background: { color: undefined } },
592+
};
593+
594+
uut.processOptions(options, CommandName.SetRoot);
595+
expect(options).toEqual({
596+
topBar: { background: { color: undefined } },
597+
});
598+
});
588599
});
589600
});
590601

@@ -748,8 +759,8 @@ describe('navigation options', () => {
748759
hideOnScroll: false,
749760
hideTopBarOnFocus: false,
750761
obscuresBackgroundDuringPresentation: false,
751-
backgroundColor: { dynamic: { light: null, dark: null } },
752-
tintColor: { dynamic: { light: null, dark: null } },
762+
backgroundColor: undefined,
763+
tintColor: undefined,
753764
placeholder: '',
754765
});
755766
});
@@ -771,8 +782,8 @@ describe('navigation options', () => {
771782
hideOnScroll: true,
772783
hideTopBarOnFocus: true,
773784
obscuresBackgroundDuringPresentation: false,
774-
backgroundColor: { dynamic: { dark: 0xffff0000, light: 0xffff0000 } },
775-
tintColor: { dynamic: { dark: 0xff00ff00, light: 0xff00ff00 } },
785+
backgroundColor: 0xffff0000,
786+
tintColor: 0xff00ff00,
776787
placeholder: 'foo',
777788
});
778789
});

lib/src/commands/OptionsProcessor.ts

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -116,33 +116,49 @@ export class OptionsProcessor {
116116

117117
private processColor(key: string, value: any, options: Record<string, any>) {
118118
if (isEqual(key, 'color') || endsWith(key, 'Color')) {
119-
const newColorObj: Record<string, any> = { dark: 'NoColor', light: 'NoColor' };
119+
if (Platform.OS === 'ios') this.processColorIOS(key, value, options);
120+
else this.processColorAndroid(key, value, options);
121+
}
122+
}
123+
124+
private processColorIOS(key: string, value: any, options: Record<string, any>) {
125+
if (value !== undefined) {
120126
if (value === null) {
121-
options[key] = newColorObj;
127+
options[key] = 'NoColor';
122128
} else if (value instanceof Object) {
123-
if ('semantic' in value || 'resource_paths' in value) {
124-
options[key] = value;
125-
return;
126-
} else if ('dynamic' in value) {
127-
for (let keyColor in value.dynamic) {
128-
newColorObj[keyColor] = this.colorService.toNativeColor(value.dynamic[keyColor]);
129-
}
130-
131-
options[key] = newColorObj;
129+
if ('dynamic' in value) {
130+
options[key].dynamic.light = this.colorService.toNativeColor(value.dynamic.light);
131+
options[key].dynamic.dark = this.colorService.toNativeColor(value.dynamic.dark);
132132
} else {
133-
for (let keyColor in value) {
134-
newColorObj[keyColor] = this.colorService.toNativeColor(value[keyColor]);
135-
}
136-
options[key] = newColorObj;
133+
options[key].light = this.colorService.toNativeColor(value.light);
134+
options[key].dark = this.colorService.toNativeColor(value.dark);
135+
options[key] = DynamicColorIOS(options[key]);
137136
}
138137
} else {
139-
let parsedColor = this.colorService.toNativeColor(value);
140-
newColorObj.light = parsedColor;
141-
newColorObj.dark = parsedColor;
142-
options[key] = newColorObj;
138+
options[key] = this.colorService.toNativeColor(value);
143139
}
140+
}
141+
}
144142

145-
if (Platform.OS === 'ios') options[key] = DynamicColorIOS(options[key]);
143+
private processColorAndroid(key: string, value: any, options: Record<string, any>) {
144+
const newColorObj: Record<string, any> = { dark: 'NoColor', light: 'NoColor' };
145+
if (value === null) {
146+
options[key] = newColorObj;
147+
} else if (value instanceof Object) {
148+
if ('semantic' in value || 'resource_paths' in value) {
149+
options[key] = value;
150+
return;
151+
} else {
152+
for (let keyColor in value) {
153+
newColorObj[keyColor] = this.colorService.toNativeColor(value[keyColor]);
154+
}
155+
options[key] = newColorObj;
156+
}
157+
} else {
158+
let parsedColor = this.colorService.toNativeColor(value);
159+
newColorObj.light = parsedColor;
160+
newColorObj.dark = parsedColor;
161+
options[key] = newColorObj;
146162
}
147163
}
148164

0 commit comments

Comments
 (0)