private void UpdateColor() { if (_renderer?.NativeView == null || _backgroundElement == null || _visualElement == null) { return; } var color = _backgroundElement.Color == Color.Default ? _visualElement.BackgroundColor == Color.Default ? Color.Default : _visualElement.BackgroundColor : _backgroundElement.Color; switch (_renderer.NativeView) { case Card mCard: if (color == Color.Default) { return; } using (var themer = new SemanticColorScheme()) { themer.SurfaceColor = _backgroundElement.Color.ToUIColor(); CardsColorThemer.ApplySemanticColorScheme(themer, mCard); } break; case ChipView mChip: if (color == Color.Default) { return; } mChip.SetBackgroundColor(_backgroundElement.Color.ToUIColor(), UIControlState.Normal); break; case MButton mButton: if (color == Color.Default) { return; } mButton.SetBackgroundColor(_backgroundElement.Color.ToUIColor()); break; default: _renderer.NativeView.BackgroundColor = UIColor.Clear; if (color == Color.Default) { return; } _renderer.NativeView.SetColor(_backgroundElement.Color); break; } }
public void UpdateGradients() { if (_renderer?.NativeView == null) { return; } var emptyGradients = _backgroundElement.Gradients == null || !_backgroundElement.Gradients.Any(); switch (_renderer.NativeView) { case Card mCard when emptyGradients: using (var themer = new SemanticColorScheme()) { themer.SurfaceColor = _visualElement.BackgroundColor.ToUIColor(); CardsColorThemer.ApplySemanticColorScheme(themer, mCard); } return; case ChipView mChip when emptyGradients: mChip.SetBackgroundColor(_visualElement.BackgroundColor.ToUIColor(), UIControlState.Normal); return; case UIView view when emptyGradients: view.BackgroundColor = _visualElement.BackgroundColor.ToUIColor(); return; } /* Chip does not accept background changes and does not support gradient */ if (_renderer.NativeView is ChipView) { return; } _renderer.NativeView.SetGradient(_backgroundElement); }