Skip to content

Commit

Permalink
Fix option processors path resolving (#6466)
Browse files Browse the repository at this point in the history
This commit fixes a bug where Options Processors didn't traverse the entire options object and thus some processors didn't work as expected. For example, processing 'topBar.rightButtons' or topBar.background.translucent didn't work.
  • Loading branch information
yogevbd authored Aug 12, 2020
1 parent 58f72f8 commit f37d465
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
31 changes: 31 additions & 0 deletions lib/src/commands/OptionsProcessor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,37 @@ describe('navigation options', () => {
});
});

it('supports multiple registered processors deep props', () => {
const options: Options = {
topBar: {
visible: false,
background: {
translucent: false,
},
},
bottomTabs: {
visible: false,
},
};

optionProcessorsRegistry.addProcessor('topBar.visible', () => true);
optionProcessorsRegistry.addProcessor('bottomTabs.visible', () => true);
optionProcessorsRegistry.addProcessor('topBar.background.translucent', () => true);

uut.processOptions(options, CommandName.SetRoot);
expect(options).toEqual({
topBar: {
visible: true,
background: {
translucent: true,
},
},
bottomTabs: {
visible: true,
},
});
});

it('processes color keys', () => {
const options: Options = {
statusBar: { backgroundColor: 'red' },
Expand Down
14 changes: 4 additions & 10 deletions lib/src/commands/OptionsProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,11 @@ export class OptionsProcessor {
parentOptions: object,
onProcess: (key: string, parentOptions: object) => void,
commandName: CommandName,
path?: string
parentPath?: string
) {
forEach(objectToProcess, (value, key) => {
this.processWithRegisteredProcessor(
key,
value,
objectToProcess,
this.resolveObjectPath(key, path),
commandName
);
const objectPath = this.resolveObjectPath(key, parentPath);
this.processWithRegisteredProcessor(key, value, objectToProcess, objectPath, commandName);
this.processColor(key, value, objectToProcess);

if (!value) {
Expand All @@ -75,8 +70,7 @@ export class OptionsProcessor {
onProcess(key, parentOptions);

if (!isEqual(key, 'passProps') && (isObject(value) || isArray(value))) {
path = this.resolveObjectPath(key, path);
this.processObject(value, parentOptions, onProcess, commandName, path);
this.processObject(value, parentOptions, onProcess, commandName, objectPath);
}
});
}
Expand Down

0 comments on commit f37d465

Please sign in to comment.