Skip to content

Commit e64de2e

Browse files
sergeymildlodev09
andauthored
feat: backgroundColor apply refactoring (#121)
* feat: backgroundColor apply refactoring * revert version --------- Co-authored-by: Jovanni Lo <lodev09@gmail.com>
1 parent c6d8b8f commit e64de2e

File tree

5 files changed

+8
-215
lines changed

5 files changed

+8
-215
lines changed

android/src/main/java/com/lodev09/truesheet/TrueSheetViewManager.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.lodev09.truesheet
33
import android.graphics.Color
44
import android.util.Log
55
import android.view.WindowManager
6+
import com.facebook.react.bridge.ColorPropConverter
67
import com.facebook.react.bridge.ReadableArray
78
import com.facebook.react.bridge.ReadableType
89
import com.facebook.react.common.MapBuilder
@@ -96,8 +97,8 @@ class TrueSheetViewManager : ViewGroupManager<TrueSheetView>() {
9697
}
9798

9899
@ReactProp(name = "background")
99-
fun setBackground(view: TrueSheetView, colorName: String) {
100-
val color = runCatching { Color.parseColor(colorName) }.getOrDefault(Color.WHITE)
100+
fun setBackground(view: TrueSheetView, colorName: Double) {
101+
val color = runCatching { ColorPropConverter.getColor(colorName, view.context) }.getOrDefault(Color.WHITE)
101102
view.setBackground(color)
102103
}
103104

ios/Extensions/UIColor+withName.swift

Lines changed: 0 additions & 204 deletions
This file was deleted.

ios/TrueSheetView.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,8 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
255255
}
256256

257257
@objc
258-
func setBackground(_ color: NSString?) {
259-
if let color {
260-
viewController.backgroundColor = UIColor(name: color as String)
261-
} else {
262-
viewController.backgroundColor = nil
263-
}
264-
258+
func setBackground(_ color: NSNumber?) {
259+
viewController.backgroundColor = RCTConvert.uiColor(color)
265260
viewController.setupBackground()
266261
}
267262

ios/TrueSheetViewManager.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ @interface RCT_EXTERN_REMAP_MODULE (TrueSheetView, TrueSheetViewManager, RCTView
3434
RCT_EXPORT_VIEW_PROPERTY(maxHeight, NSNumber)
3535
RCT_EXPORT_VIEW_PROPERTY(sizes, NSArray)
3636
RCT_EXPORT_VIEW_PROPERTY(blurTint, NSString)
37-
RCT_EXPORT_VIEW_PROPERTY(background, NSString)
37+
RCT_EXPORT_VIEW_PROPERTY(background, NSNumber)
3838
RCT_EXPORT_VIEW_PROPERTY(cornerRadius, NSNumber)
3939
RCT_EXPORT_VIEW_PROPERTY(grabber, BOOL)
4040
RCT_EXPORT_VIEW_PROPERTY(dismissible, BOOL)

src/TrueSheet.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
type NativeSyntheticEvent,
1010
type LayoutChangeEvent,
1111
type ColorValue,
12+
processColor,
1213
} from 'react-native'
1314

1415
import type { TrueSheetProps, SizeInfo } from './TrueSheet.types'
@@ -250,7 +251,7 @@ export class TrueSheet extends PureComponent<TrueSheetProps, TrueSheetState> {
250251
scrollableHandle={this.state.scrollableHandle}
251252
sizes={sizes}
252253
blurTint={blurTint}
253-
background={backgroundColor}
254+
background={(backgroundColor ? processColor(backgroundColor) : undefined) as any}
254255
cornerRadius={cornerRadius}
255256
contentHeight={this.state.contentHeight}
256257
footerHeight={this.state.footerHeight}

0 commit comments

Comments
 (0)