Skip to content

Commit 8e0d7f8

Browse files
authored
Fix macOS ActivityIndicator to color properly in different themes (#13)
* Fix macOS ActivityIndicator to color properly in different themes * Removed prop setter override * Add color setter to cause redisplay
1 parent c937081 commit 8e0d7f8

File tree

2 files changed

+46
-14
lines changed

2 files changed

+46
-14
lines changed

RNTester/js/ActivityIndicatorExample.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import React, {Component} from 'react';
1414
import {ActivityIndicator, StyleSheet, View} from 'react-native';
15+
const Platform = require('Platform');
1516

1617
/**
1718
* Optional Flowtype state and timer types definition
@@ -99,8 +100,18 @@ exports.examples = [
99100
render() {
100101
return (
101102
<View style={styles.horizontal}>
102-
<ActivityIndicator color="#0000ff" />
103-
<ActivityIndicator color="#aa00aa" />
103+
<ActivityIndicator
104+
color={
105+
Platform.OS === 'macos'
106+
? {dynamic: {light: 'black', dark: 'white'}}
107+
: '#0000ff'
108+
}
109+
/>
110+
<ActivityIndicator
111+
color={
112+
Platform.OS === 'macos' ? {semantic: 'textColor'} : '#aa00aa'
113+
}
114+
/>
104115
<ActivityIndicator color="#aa3300" />
105116
<ActivityIndicator color="#00aa00" />
106117
</View>
@@ -148,7 +159,7 @@ exports.examples = [
148159
size="large"
149160
/>
150161
);
151-
}
162+
},
152163
},
153164
{
154165
platform: 'android',
@@ -184,5 +195,13 @@ const styles = StyleSheet.create({
184195
flexDirection: 'row',
185196
justifyContent: 'space-around',
186197
padding: 8,
198+
...Platform.select({
199+
macos: {
200+
backgroundColor: {semantic: 'windowBackgroundColor'},
201+
},
202+
default: {
203+
backgroundColor: undefined,
204+
},
205+
}),
187206
},
188207
});

React/Views/RCTActivityIndicatorView.m

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,31 @@ - (void)setActivityIndicatorViewStyle:(UIActivityIndicatorViewStyle)activityIndi
6666
}
6767
}
6868

69-
- (void)setColor:(UIColor*)color
69+
- (void)setColor: (UIColor*)color
7070
{
71-
_color = [color colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
72-
CIFilter *colorPoly = [CIFilter filterWithName:@"CIColorPolynomial"];
73-
[colorPoly setDefaults];
74-
CIVector *redVector = [CIVector vectorWithX:color.redComponent Y:0 Z:0 W:0];
75-
CIVector *greenVector = [CIVector vectorWithX:color.greenComponent Y:0 Z:0 W:0];
76-
CIVector *blueVector = [CIVector vectorWithX:color.blueComponent Y:0 Z:0 W:0];
77-
[colorPoly setValue:redVector forKey:@"inputRedCoefficients"];
78-
[colorPoly setValue:greenVector forKey:@"inputGreenCoefficients"];
79-
[colorPoly setValue:blueVector forKey:@"inputBlueCoefficients"];
80-
self.contentFilters = @[colorPoly];
71+
if (_color != color) {
72+
_color = color;
73+
[self setNeedsDisplay:YES];
74+
}
75+
}
76+
77+
- (void)updateLayer
78+
{
79+
[super updateLayer];
80+
if (_color) {
81+
CGFloat r, g, b, a;
82+
[[_color colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:&r green:&g blue:&b alpha:&a];
83+
84+
CIFilter *colorPoly = [CIFilter filterWithName:@"CIColorPolynomial"];
85+
[colorPoly setDefaults];
86+
CIVector *redVector = [CIVector vectorWithX:r Y:0 Z:0 W:0];
87+
CIVector *greenVector = [CIVector vectorWithX:g Y:0 Z:0 W:0];
88+
CIVector *blueVector = [CIVector vectorWithX:b Y:0 Z:0 W:0];
89+
[colorPoly setValue:redVector forKey:@"inputRedCoefficients"];
90+
[colorPoly setValue:greenVector forKey:@"inputGreenCoefficients"];
91+
[colorPoly setValue:blueVector forKey:@"inputBlueCoefficients"];
92+
self.contentFilters = @[colorPoly];
93+
}
8194
}
8295

8396
- (void)setHidesWhenStopped:(BOOL)hidesWhenStopped

0 commit comments

Comments
 (0)