nathantannar4 / InputBarAccessoryView

A simple and easily customizable InputAccessoryView for making powerful input bars with autocomplete and attachments
MIT License
1.15k stars 229 forks source link

Changing access modifier of requiredInputTextViewHeight from public to open? #253

Open MyAnJuN opened 7 months ago

MyAnJuN commented 7 months ago

1. my feature request related to a problem i have a feature, that's adds a emojiButton into middleContentView. so i set a customeView which contains inputTextView and emojiButton,and call setMiddleContentView(self.customeView, animated: false). it works,but maxTextViewHeight = 88 did't works. so i read the source code, find that problem lies in the following code snipped.

IMG_79F91966B5C2-1

    public var requiredInputTextViewHeight: CGFloat {
        guard middleContentView == inputTextView else {
            return middleContentView?.intrinsicContentSize.height ?? 0
        }
        let maxTextViewSize = CGSize(width: inputTextView.bounds.width, height: .greatestFiniteMagnitude)
        return inputTextView.sizeThatFits(maxTextViewSize).height.rounded(.down)
    }

2. solution Because i set customeView so middleContentView == inputTextView alwals false. so i need override this requiredInputTextViewHeight property in the following code snipped.

    public var requiredInputTextViewHeight: CGFloat {
        let maxTextViewSize = CGSize(width: inputTextView.bounds.width, height: .greatestFiniteMagnitude)
        return inputTextView.sizeThatFits(maxTextViewSize).height.rounded(.down)
    }

but it's access modifier is public, so can changing it to open?

nathantannar4 commented 7 months ago

It is expected that custom views provide an intrinsicContentSize. Are you able to implement intrinsicContentSize on your custom view?

MyAnJuN commented 7 months ago

Currently, my custom view is not defined as a separate class. It is just defined as a UIView. Are you suggesting that I need to create a custom class that inherits from InputTextView and override intrinsicContentSize?

nathantannar4 commented 7 months ago

You don't need to inherit from InputTextView, you can just inherit from UIView

MyAnJuN commented 7 months ago

After applying the suggested modifications, the intrinsicContentSize of the custom view limits the height. However, the height of the view still increases as the input text grows in UI.

    override var intrinsicContentSize: CGSize {
        let maxTextViewSize = CGSize(width: inputTextView.bounds.width, height: .greatestFiniteMagnitude)
        let height = inputTextView.sizeThatFits(maxTextViewSize).height.rounded(.down)
        return CGSize(width: size.width, height: min(height, 88))
    }
nathantannar4 commented 7 months ago

Sorry I'm unclear as to what the problem is and what you have changed.

However, the height of the view still increases as the input text grows in UI

Are you trying to limit how high the input text view can grow?