Skip to content

Commit

Permalink
feat: add background color
Browse files Browse the repository at this point in the history
  • Loading branch information
haileyok committed Sep 13, 2024
1 parent d48fc66 commit 3965014
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ PODS:
- React-Mapbuffer (0.73.5):
- glog
- React-debug
- react-native-uitextview (1.1.5):
- react-native-uitextview (1.2.1):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
Expand Down Expand Up @@ -1251,7 +1251,7 @@ SPEC CHECKSUMS:
React-jsinspector: 32db5e364bcae8fca8cdf8891830636275add0c5
React-logger: 0331362115f0f5b392bd7ed14636d1a3ea612479
React-Mapbuffer: 7c35cd53a22d0be04d3f26f7881c7fb7dd230216
react-native-uitextview: 074935787667522fdde4625c7e57eb341270f892
react-native-uitextview: a743682a89aac66e3ec6c94e5ac9c190c1fbdf01
React-nativeconfig: 1166714a4f7ea57a0df5c2cb44fbc70f98d580f9
React-NativeModulesApple: 726664e9829eb5eed8170241000e46ead269a05f
React-perflogger: 0dd9f1725d55f8264b81efadd373fe1d9cca7dc2
Expand Down
34 changes: 34 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,37 @@ export default function App() {
</Text>
</View>

<View>
<RNText style={styles.subheader}>Base, backgroundColor</RNText>
<RNText style={[styles.text, styles.backgroundColor]}>
Hello world!
</RNText>
<RNText style={[styles.text]}>
Hello world!{' '}
<RNText style={[styles.text, styles.backgroundColor]}>
And more!
</RNText>
</RNText>
</View>
<View>
<Text style={styles.subheader}>UITextView, backgroundColor</Text>
<Text
selectable
uiTextView
style={[styles.text, styles.backgroundColor]}>
Hello world!
</Text>
<Text selectable uiTextView style={[styles.text]}>
Hello world!{' '}
<Text
selectable
uiTextView
style={[styles.text, styles.backgroundColor]}>
And more!
</Text>
</Text>
</View>

<View>
<RNText style={styles.subheader}>Base, textDecorationLine</RNText>
<RNText style={[styles.text, styles.underlined]}>
Expand Down Expand Up @@ -633,5 +664,8 @@ const styles = StyleSheet.create({
},
lineHeight30: {
lineHeight: 30
},
backgroundColor: {
backgroundColor: 'yellow'
}
})
1 change: 1 addition & 0 deletions ios/RNUITextViewChildShadow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class RNUITextViewChildShadow: RCTShadowView {
@objc var textDecorationLine: RCTTextDecorationLineType = .none
@objc var textDecorationStyle: String = "solid"
@objc var textDecorationColor: UIColor = .black
@objc var backgroundColor: UIColor?

override func isYogaLeafNode() -> Bool {
return true
Expand Down
1 change: 1 addition & 0 deletions ios/RNUITextViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ @interface RCT_EXTERN_MODULE(RNUITextViewChildManager, RCTViewManager)
RCT_REMAP_SHADOW_PROPERTY(textDecorationLine, textDecorationLine, RCTTextDecorationLineType)
RCT_REMAP_SHADOW_PROPERTY(textDecorationStyle, textDecorationStyle, NSString)
RCT_REMAP_SHADOW_PROPERTY(textDecorationColor, textDecorationColor, UIColor)
RCT_REMAP_SHADOW_PROPERTY(backgroundColor, backgroundColor, UIColor)

RCT_EXPORT_VIEW_PROPERTY(text, NSString)
RCT_EXPORT_VIEW_PROPERTY(onPress, RCTBubblingEventBlock)
Expand Down
4 changes: 4 additions & 0 deletions ios/RNUITextViewShadow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ class RNUITextViewShadow: RCTShadowView {
attributes[.strikethroughStyle] = child.getTextDecorationStyle()
attributes[.strikethroughColor] = child.getTextDecorationColor()
}

if child.backgroundColor != nil {
attributes[.backgroundColor] = child.backgroundColor
}

// Create the attributed string with the generic attributes
let string = NSMutableAttributedString(string: child.text, attributes: attributes)
Expand Down

0 comments on commit 3965014

Please sign in to comment.