Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.lodev09.truesheet
import android.graphics.Color
import android.util.Log
import android.view.WindowManager
import com.facebook.react.bridge.ColorPropConverter
import com.facebook.react.bridge.ReadableArray
import com.facebook.react.bridge.ReadableType
import com.facebook.react.common.MapBuilder
Expand Down Expand Up @@ -96,8 +97,8 @@ class TrueSheetViewManager : ViewGroupManager<TrueSheetView>() {
}

@ReactProp(name = "background")
fun setBackground(view: TrueSheetView, colorName: String) {
val color = runCatching { Color.parseColor(colorName) }.getOrDefault(Color.WHITE)
fun setBackground(view: TrueSheetView, colorName: Double) {
val color = runCatching { ColorPropConverter.getColor(colorName, view.context) }.getOrDefault(Color.WHITE)
view.setBackground(color)
}

Expand Down
204 changes: 0 additions & 204 deletions ios/Extensions/UIColor+withName.swift

This file was deleted.

9 changes: 2 additions & 7 deletions ios/TrueSheetView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,8 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
}

@objc
func setBackground(_ color: NSString?) {
if let color {
viewController.backgroundColor = UIColor(name: color as String)
} else {
viewController.backgroundColor = nil
}

func setBackground(_ color: NSNumber?) {
viewController.backgroundColor = RCTConvert.uiColor(color)
viewController.setupBackground()
}

Expand Down
2 changes: 1 addition & 1 deletion ios/TrueSheetViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ @interface RCT_EXTERN_REMAP_MODULE (TrueSheetView, TrueSheetViewManager, RCTView
RCT_EXPORT_VIEW_PROPERTY(maxHeight, NSNumber)
RCT_EXPORT_VIEW_PROPERTY(sizes, NSArray)
RCT_EXPORT_VIEW_PROPERTY(blurTint, NSString)
RCT_EXPORT_VIEW_PROPERTY(background, NSString)
RCT_EXPORT_VIEW_PROPERTY(background, NSNumber)
RCT_EXPORT_VIEW_PROPERTY(cornerRadius, NSNumber)
RCT_EXPORT_VIEW_PROPERTY(grabber, BOOL)
RCT_EXPORT_VIEW_PROPERTY(dismissible, BOOL)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lodev09/react-native-true-sheet",
"version": "1.0.3",
"version": "1.0.4",
"description": "The true native bottom sheet experience for your React Native Apps.",
"source": "./src/index.ts",
"main": "./lib/commonjs/index.js",
Expand Down
3 changes: 2 additions & 1 deletion src/TrueSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
type NativeSyntheticEvent,
type LayoutChangeEvent,
type ColorValue,
processColor,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
processColor,
type ProcessedColorValue,

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace the type with this:

interface TrueSheetNativeViewProps
  extends Omit<TrueSheetProps, 'onPresent' | 'onSizeChange' | 'backgroundColor'> {
  contentHeight?: number
  footerHeight?: number
  background?: ProcessedColorValue | null
  scrollableHandle: number | null
  onPresent: (event: SizeChangeEvent) => void
  onSizeChange: (event: SizeChangeEvent) => void
  onContainerSizeChange: (event: ContainerSizeChangeEvent) => void
}

} from 'react-native'

import type { TrueSheetProps, SizeInfo } from './TrueSheet.types'
Expand Down Expand Up @@ -250,7 +251,7 @@ export class TrueSheet extends PureComponent<TrueSheetProps, TrueSheetState> {
scrollableHandle={this.state.scrollableHandle}
sizes={sizes}
blurTint={blurTint}
background={backgroundColor}
background={(backgroundColor ? processColor(backgroundColor) : undefined) as any}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe change the background type in TrueSheetNativeViewProps instead of casting to any

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you change this property in TrueSheetNativeViewProps so that its type is number instead of ColorType, the user won't be able to use it as a regular color property. I don't see any problem with casting to any because it's part of the internal implementation and won't be exposed externally.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the background prop is actually just a prop for the native component. The user facing prop is backgroundColor.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
background={(backgroundColor ? processColor(backgroundColor) : undefined) as any}
background={(backgroundColor ? processColor(backgroundColor) : undefined)}

cornerRadius={cornerRadius}
contentHeight={this.state.contentHeight}
footerHeight={this.state.footerHeight}
Expand Down