Chart Settings screen
You can customize the Chart Settings screen with one of the following approaches:
- Provide your own solution to change the Settings using customizing ChartToolBar. (Not covered in this document).
- Make a custom setup for the ChartSettings module and integrate it using customizing ChartToolBar. (Not covered in this document).
- Set up the Settings screen using ChartScreen.DataSource api.
ChartScreen.DataSource
Overview
ChartScreen.DataSource allows you to describe the layout of the built-in Settings screen for ChartScreen. It focuses only on sections and rows; no settings values are specified here. When passed to ChartScreen.makeScreen(...), the module builds and displays the UI using the custom layout.
If you provide a custom ChartToolBar.DataSource and implement your own Settings UI, ChartScreen.DataSource will not affect anything.
Relation to ChartSettings.DataSource
ChartSettings.DataSource requires more context (e.g., aggregation, instrument, candles). ChartScreen component bridges the gap: it conforms to ChartSettings.DataSource by using its own internal state (instrument, aggregation, candles, settings) and, if provided, the settingsContent layout from ChartScreen.DataSource.
Protocol shape
public protocol ChartScreen.DataSource {var settingsContent: [ChartSettings.Section]? { get }}
How it is used
- When provided to
ChartScreen.makeScreen(...), the module uses it to:- Optionally create a custom
settingsContentlayout for the Settings screen sections and rows
- Optionally create a custom
Custom toolbar scenario
- If you supply a custom
ChartToolBar.DataSource(viaChartScreen.makeScreen(toolbarDataSource: ...)):- The default toolbar (with the default Settings item) is replaced by your custom toolbar.
- Therefore,
ChartScreen.DataSourcehas no effect for custom settings screen. - If you implement your own Settings UI, you can ignore
ChartScreen.DataSourceentirely.
Examples
Implementing ChartScreen.DataSource to return only the built-in Settings screen layout:
final class CustomChartScreenDataSource: ChartScreen.DataSource {var settingsContent: [ChartSettings.Section]? {// Return nil to use the default content// or return a custom sections layoutnil}}
Applying to the chart screen:
let viewController = ChartScreen.makeScreen(dataProvider: provider,dataStorage: storage,settingsManager: settingsManager,dataSource: CustomChartScreenDataSource())
Notes
- If
dataSourceisnil, the module falls back to its default Settings screen content. settingsContentallows you to specify which sections/rows the built-in Settings screen will show. Returnnilto use the default layout.- Providing a custom toolbar without using the built-in Settings screen means that
ChartScreen.DataSource settingsContentwon’t be used.