Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix graphs on new architecture with interop layer #1007

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 91 additions & 48 deletions ios/ReactNativeCharts/RNBarLineChartBaseManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,65 +7,108 @@ import Foundation
import DGCharts

protocol RNBarLineChartBaseManager {
var _bridge : RCTBridge? {get}
var _bridge : RCTBridge? {get}
}

extension RNBarLineChartBaseManager {
func _moveViewToX(_ reactTag: NSNumber, xValue: NSNumber) {
_bridge?.uiManager.addUIBlock { (uiManager: RCTUIManager?, viewRegistry:[NSNumber : UIView]?) in
let view: RNBarLineChartViewBase = viewRegistry![reactTag] as! RNBarLineChartViewBase;
(view.chart as! BarLineChartViewBase).moveViewToX(xValue.doubleValue);
func _moveViewToX(_ reactTag: NSNumber, xValue: NSNumber) {
_bridge?.uiManager.addUIBlock { (uiManager: RCTUIManager?, viewRegistry:[NSNumber : UIView]?) in

guard let view: RNBarLineChartViewBase = viewRegistry?[reactTag] as? RNBarLineChartViewBase,
let barLineChart = view.chart as? BarLineChartViewBase
else {
return
}

barLineChart.moveViewToX(xValue.doubleValue);
}
}
}

func _moveViewTo(_ reactTag: NSNumber, xValue: NSNumber, yValue: NSNumber, axisDependency: NSString) {
_bridge?.uiManager.addUIBlock { (uiManager: RCTUIManager?, viewRegistry:[NSNumber : UIView]?) in
let view: RNBarLineChartViewBase = viewRegistry![reactTag] as! RNBarLineChartViewBase;
(view.chart as! BarLineChartViewBase).moveViewTo(xValue: xValue.doubleValue, yValue: yValue.doubleValue, axis: BridgeUtils.parseAxisDependency(axisDependency as String));

func _moveViewTo(_ reactTag: NSNumber, xValue: NSNumber, yValue: NSNumber, axisDependency: NSString) {
_bridge?.uiManager.addUIBlock { (uiManager: RCTUIManager?, viewRegistry:[NSNumber : UIView]?) in

guard let view: RNBarLineChartViewBase = viewRegistry?[reactTag] as? RNBarLineChartViewBase,
let barLineChart = view.chart as? BarLineChartViewBase
else {
return
}

barLineChart.moveViewTo(xValue: xValue.doubleValue, yValue: yValue.doubleValue, axis: BridgeUtils.parseAxisDependency(axisDependency as String));
}
}
}

func _moveViewToAnimated(_ reactTag: NSNumber, xValue: NSNumber, yValue: NSNumber, axisDependency: NSString, duration: NSNumber) {
_bridge?.uiManager.addUIBlock { (uiManager: RCTUIManager?, viewRegistry:[NSNumber : UIView]?) in
let view: RNBarLineChartViewBase = viewRegistry![reactTag] as! RNBarLineChartViewBase;
(view.chart as! BarLineChartViewBase).moveViewToAnimated(xValue: xValue.doubleValue, yValue: yValue.doubleValue, axis: BridgeUtils.parseAxisDependency(axisDependency as String), duration: duration.doubleValue / 1000.0);

func _moveViewToAnimated(_ reactTag: NSNumber, xValue: NSNumber, yValue: NSNumber, axisDependency: NSString, duration: NSNumber) {
_bridge?.uiManager.addUIBlock { (uiManager: RCTUIManager?, viewRegistry:[NSNumber : UIView]?) in

guard let view: RNBarLineChartViewBase = viewRegistry?[reactTag] as? RNBarLineChartViewBase,
let barLineChart = view.chart as? BarLineChartViewBase
else {
return
}

barLineChart.moveViewToAnimated(xValue: xValue.doubleValue, yValue: yValue.doubleValue, axis: BridgeUtils.parseAxisDependency(axisDependency as String), duration: duration.doubleValue / 1000.0);
}
}
}

func _centerViewTo(_ reactTag: NSNumber, xValue: NSNumber, yValue: NSNumber, axisDependency: NSString) {
_bridge?.uiManager.addUIBlock { (uiManager: RCTUIManager?, viewRegistry:[NSNumber : UIView]?) in
let view: RNBarLineChartViewBase = viewRegistry![reactTag] as! RNBarLineChartViewBase;
(view.chart as! BarLineChartViewBase).centerViewTo(xValue: xValue.doubleValue, yValue: yValue.doubleValue, axis: BridgeUtils.parseAxisDependency(axisDependency as String));

func _centerViewTo(_ reactTag: NSNumber, xValue: NSNumber, yValue: NSNumber, axisDependency: NSString) {
_bridge?.uiManager.addUIBlock { (uiManager: RCTUIManager?, viewRegistry:[NSNumber : UIView]?) in

guard let view: RNBarLineChartViewBase = viewRegistry?[reactTag] as? RNBarLineChartViewBase,
let barLineChart = view.chart as? BarLineChartViewBase
else {
return
}

barLineChart.centerViewTo(xValue: xValue.doubleValue, yValue: yValue.doubleValue, axis: BridgeUtils.parseAxisDependency(axisDependency as String));
}
}
}

func _centerViewToAnimated(_ reactTag: NSNumber, xValue: NSNumber, yValue: NSNumber, axisDependency: NSString, duration: NSNumber) {
_bridge?.uiManager.addUIBlock { (uiManager: RCTUIManager?, viewRegistry:[NSNumber : UIView]?) in
let view: RNBarLineChartViewBase = viewRegistry![reactTag] as! RNBarLineChartViewBase;
(view.chart as! BarLineChartViewBase).centerViewToAnimated(xValue: xValue.doubleValue, yValue: yValue.doubleValue, axis: BridgeUtils.parseAxisDependency(axisDependency as String), duration: duration.doubleValue / 1000.0);

func _centerViewToAnimated(_ reactTag: NSNumber, xValue: NSNumber, yValue: NSNumber, axisDependency: NSString, duration: NSNumber) {
_bridge?.uiManager.addUIBlock { (uiManager: RCTUIManager?, viewRegistry:[NSNumber : UIView]?) in

guard let view: RNBarLineChartViewBase = viewRegistry?[reactTag] as? RNBarLineChartViewBase,
let barLineChart = view.chart as? BarLineChartViewBase
else {
return
}

barLineChart.centerViewToAnimated(xValue: xValue.doubleValue, yValue: yValue.doubleValue, axis: BridgeUtils.parseAxisDependency(axisDependency as String), duration: duration.doubleValue / 1000.0);
}
}
}

func _fitScreen(_ reactTag: NSNumber) {
_bridge?.uiManager.addUIBlock { (uiManager: RCTUIManager?, viewRegistry:[NSNumber : UIView]?) in
let view: RNBarLineChartViewBase = viewRegistry![reactTag] as! RNBarLineChartViewBase;
(view.chart as! BarLineChartViewBase).fitScreen();

func _fitScreen(_ reactTag: NSNumber) {
_bridge?.uiManager.addUIBlock { (uiManager: RCTUIManager?, viewRegistry:[NSNumber : UIView]?) in
guard let view: RNBarLineChartViewBase = viewRegistry?[reactTag] as? RNBarLineChartViewBase,
let barLineChart = view.chart as? BarLineChartViewBase
else {
return
}

barLineChart.fitScreen();
}
}
}

func _highlights(_ reactTag: NSNumber, config: NSArray) {
_bridge?.uiManager.addUIBlock { (uiManager: RCTUIManager?, viewRegistry:[NSNumber : UIView]?) in
let view: RNBarLineChartViewBase = viewRegistry![reactTag] as! RNBarLineChartViewBase;
(view.chart as! BarLineChartViewBase).highlightValues(HighlightUtils.getHighlights(config));

func _highlights(_ reactTag: NSNumber, config: NSArray) {
_bridge?.uiManager.addUIBlock { (uiManager: RCTUIManager?, viewRegistry:[NSNumber : UIView]?) in
guard let view: RNBarLineChartViewBase = viewRegistry?[reactTag] as? RNBarLineChartViewBase,
let barLineChart = view.chart as? BarLineChartViewBase
else {
return
}
barLineChart.highlightValues(HighlightUtils.getHighlights(config));
}
}
}

func _setDataAndLockIndex(_ reactTag: NSNumber, data: NSDictionary) {
_bridge?.uiManager.addUIBlock { (uiManager: RCTUIManager?, viewRegistry:[NSNumber : UIView]?) in
let view: RNBarLineChartViewBase = viewRegistry![reactTag] as! RNBarLineChartViewBase;
view.setDataAndLockIndex(data);

func _setDataAndLockIndex(_ reactTag: NSNumber, data: NSDictionary) {
_bridge?.uiManager.addUIBlock { (uiManager: RCTUIManager?, viewRegistry:[NSNumber : UIView]?) in
guard
let view = viewRegistry?[reactTag] as? RNBarLineChartViewBase
else {
return
}
view.setDataAndLockIndex(data);
}
}
}
}


Expand Down
5 changes: 5 additions & 0 deletions ios/ReactNativeCharts/line/RNLineChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class RNLineChartView: RNBarLineChartViewBase {

}

override func layoutSubviews() {
super.layoutSubviews()
_chart.frame = self.bounds // Adjust the chart's frame to fill the entire component's bounds
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Expand Down