slackhq / SlackTextViewController

⛔️**DEPRECATED** ⛔️ A drop-in UIViewController subclass with a growing text input view and other useful messaging features
https://slack.com/
MIT License
8.32k stars 1.08k forks source link

iOS 11 breaks slacktextviewcontroller #604

Closed JosephShenton closed 7 years ago

JosephShenton commented 7 years ago

Description

Cannot press the textview due to there being an invisible view over it.

Reproducible in:

Steps to reproduce:

  1. Install iOS 11
  2. Run SlackTextViewController Demo
  3. Try clicking the textview

Expected result:

Expected me to be able to send messages etc

Actual result:

Couldn't open textview

Attachments:

img_6866

hipwelljo commented 7 years ago

Confirmed 😮

JosephShenton commented 7 years ago

@hipwelljo however it works on apps built pre iOS 11 which is wierd

claudiumatei commented 7 years ago

It seems that this bug is caused by a new subview which is added only for iOS 11

On iOS 10, the subviews array for textInputbar looks like this:

(lldb) po self.textInputbar.subviews <__NSArrayM 0x170c5cbf0>( <_UIBarBackground: 0x15fdbc650; frame = (0 0; 375 48); userInteractionEnabled = NO; layer = <CALayer: 0x1746370a0>>, <UIView: 0x161a03f50; frame = (0 0; 375 0); clipsToBounds = YES; hidden = YES; layer = <CALayer: 0x174636340>>, <UIButton: 0x161a04fb0; frame = (0 48; 0 0); opaque = NO; layer = <CALayer: 0x174635e20>>, <UIButton: 0x161a05530; frame = (375 11; 0 30); opaque = NO; layer = <CALayer: 0x174635d40>>, <SLKTextView: 0x16085f400; baseClass = UITextView; frame = (8 5; 359 38); text = ''; clipsToBounds = YES; gestureRecognizers = <NSArray: 0x174851640>; layer = <CALayer: 0x174636ec0>; contentOffset: {0, 0}; contentSize: {359, 38}>, <UILabel: 0x161a05ab0; frame = (367 5; 0 0); userInteractionEnabled = NO; layer = <_UILabelLayer: 0x174482760>> )

On iOS 11, the subviews array for textInputbar has a new element, which is right at the top of view hierarchy.

(lldb) po self.textInputbar.subviews <__NSArrayM 0x60800287a9c0>( <_UIBarBackground: 0x7fabd172c630; frame = (0 0; 375 48); userInteractionEnabled = NO; layer = <CALayer: 0x608000a2fc20>>, <UIView: 0x7fabd17224e0; frame = (0 0; 375 0); clipsToBounds = YES; hidden = YES; layer = <CALayer: 0x608000e25f20>>, <UIButton: 0x7fabd1720590; frame = (0 48; 0 0); opaque = NO; layer = <CALayer: 0x608000e35ea0>>, <UIButton: 0x7fabd150e3b0; frame = (375 11; 0 30); opaque = NO; layer = <CALayer: 0x6000012323a0>>, <SLKTextView: 0x7fabcf864000; baseClass = UITextView; frame = (8 5; 359 38); text = ''; clipsToBounds = YES; gestureRecognizers = <NSArray: 0x608002662580>; layer = <CALayer: 0x608000c32640>; contentOffset: {0, 0}; contentSize: {359, 38}; adjustedContentInset: {0, 0, 0, 0}>, <UILabel: 0x7fabd153a1e0; frame = (367 5; 0 0); userInteractionEnabled = NO; layer = <_UILabelLayer: 0x60000068d570>>, <_UIToolbarContentView: 0x7fabd17276d0; frame = (0 0; 375 48); layer = <CALayer: 0x608000a291e0>> )

Notice the _UIToolbarContentView subview, right at the top (aka last object from subviews array)!

A quick temporary workaround is to do something like this in your controller: [self.textInputbar sendSubviewToBack:[self.textInputbar.subviews lastObject]];

Or: [self.textInputbar bringSubviewToFront:self.textInputbar.rightButton]; [self.textInputbar bringSubviewToFront:self.textInputbar.textView];

Hope this is good enough until we have a proper fix

markdaws commented 7 years ago

@claudiumatei - thanks for the workaround. If I add this code, I can now type in the input box (in the simulator using a keyboard) but the keyboard does not appear on on a device when you click on the text input box. Do you have the same problem or know of a workaround to make the keyboard appear?

hipwelljo commented 7 years ago

The workaround committed by paulcarpenter is working nicely for me.

tylerjames commented 7 years ago

This workaround is not going to play well with the newly announced iPhone X. You're not allowed to put any interaction elements in that area due to the rounded screen.

I think our days of putting a text field right at the bottom of the screen are over. You'll notice that Apple doesn't even do this in the Messages app anymore, they have that annoying iMessage apps bar.

eliot1019 commented 7 years ago

It seems that inserting or deleting rows causes the entire tableView to stop responding as something is wrong with layout of the views.

dzenbot commented 7 years ago

Any review/testing of the above fix would be helpful ☝️

hipwelljo commented 7 years ago

@dzenbot Haven't tried it, but wanted to note a UIView subclass would be a solid background instead of the translucent blurred toolbar. (Though it seemed the toolbar wasn't actually translucent anyways, I didn't see elements through it in my app). Just wanted to be sure that's what is desired now.

dzenbot commented 7 years ago

So people may want to have blurred toolbar effects, indeed. I though of that, and this should be as simple as making the view translucent and add a UIVisualEffectView to allow that effect.

This change will certainly not be backwards compatible for those use cases, but there is a simple workaround.

abildgaard commented 7 years ago

I tested #624 and it works for our application - thanks

erikhric commented 7 years ago

I programmatically called becomeFirstResponder() on the textfield. Keyboard appeared, but the textfield was still on the bottom 😾

arthurgarzajr commented 7 years ago

I am using cocoa pods. What do I need to do to get this update?

iospro commented 7 years ago

To solve the problem for iOS11 (compatible with lower versions) you only need to make layoutSubview right after UIToolBar was added as a subview to UI hierarchy.

In this case _UIToolbarContentView lowers to the first subview of UIToolBar, and you can add all your subviews higher as before.

For example in ObjC,

    UIToolbar *toolbar = [UIToolbar new];
    [self addSubview: toolbar];
    [toolbar layoutIfNeeded];

    <here one can add all subviews needed>
dzenbot commented 7 years ago

Interesting. Still, it seemed better to simply stop using UIToolbar altogether. We were only using it for getting the built-in blurring effect and the hairline anyway. With the current fix, only the blurring effect would need to be added adhoc by developers, if needed.

Balasubramanian93 commented 6 years ago

Hi Guys,

I am facing different issue. Contents drawn on the CGContext of the UIImageView got disappeared. I have attached the video which demonstrates the issue i was facing in my side. I am getting this issue only in iOS 11 iPad. I could not reproduce the issue in iPod/iPhone with iOS 11. Can you please let me know if you have any idea on this?

Video: https://www.dropbox.com/s/7nhnaqdhh8ha7u1/Untitled.zip?dl=0