hhunaid / react-native-image-crop-tools

Native-ish Image Crop Tools for react native
171 stars 58 forks source link

Android aspectRatio typings should accept null #56

Closed efstathiosntonas closed 2 years ago

efstathiosntonas commented 2 years ago

If the aspectRatio prop on Android is {width: 9, height: 16} then the "free" aspect ratio is not working when keepAspectRatio is false.

native code responsible:

@ReactProp(name = KEEP_ASPECT_RATIO_PROP)
    fun setFixedAspectRatio(view: CropImageView, fixed: Boolean) {
        view.setFixedAspectRatio(fixed)
    }

    @ReactProp(name = ASPECT_RATIO_PROP)
    fun setAspectRatio(view: CropImageView, aspectRatio: ReadableMap?) {
        if (aspectRatio != null) {
            view.setAspectRatio(aspectRatio.getInt("width"), aspectRatio.getInt("height"))
        }else {
            view.clearAspectRatio() <<<<--------- if we set aspectRatio to null on props it works as charm since we hit here
        }
    }

Setting {width: 0, height: 0} on Android will throw error that the values must be bigger than 0, on iOS there is no issue with this.

Since types have

aspectRatio?: {
        width: number;
        height: number;
    };

if we set it to null then we get a typing error.

Proposal: Allow above prop to accept null.

edit: disregard the issue, i've just used undefined :face-palm:

I think this should be documented though, maybe the user wants to change the ratio on the fly as per the gifs on README

hhunaid commented 2 years ago

I see that you closed it. Is it fixed or did you find a workaround?

efstathiosntonas commented 2 years ago

@hhunaid no need to accept null, undefined will work too