Skip to content

Commit 158588c

Browse files
Merge pull request #212 from virdesai/keyboard-fix-and-other-cleanup
KeyboardCompatibleView initialHeight setting with keyboard closed and new onLayout height
2 parents 9caec80 + ead4805 commit 158588c

File tree

6 files changed

+16
-20
lines changed

6 files changed

+16
-20
lines changed

docs/cookbook.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,11 +1326,14 @@ For setup regarding push notifications, first of all make sure you have followed
13261326

13271327
### Requirements
13281328

1329-
- User must be a member of channel, if he expects a push notification for a message on that channel.
1329+
- User must be a member of channel if they expect a push notification for a message on that channel.
13301330

13311331
- We only send a push notification, when user is **NOT** connected to chat, or in other words, if user does **NOT** have any active WS (websocket) connection. WS connection is established when you do
13321332

1333-
`await client.setUser({ id: 'user_id' })`.
1333+
```js
1334+
await client.setUser({ id: 'user_id' })
1335+
await client.addDevice(token.token, token.os === 'ios' ? 'apn' : 'firebase')
1336+
```
13341337

13351338
### Caveats
13361339

src/components/ChannelInner.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ class ChannelInner extends PureComponent {
155155
threadMessages: [],
156156
threadLoadingMore: false,
157157
threadHasMore: true,
158-
kavEnabled: true,
159158
/** We save the events in state so that we can display event message
160159
* next to the message after which it was received, in MessageList.
161160
*
@@ -651,8 +650,6 @@ class ChannelInner extends PureComponent {
651650
this.props.disableIfFrozenChannel,
652651
});
653652

654-
renderComponent = () => this.props.children;
655-
656653
renderLoading = () => {
657654
const Indicator = this.props.LoadingIndicator;
658655
return <Indicator listType="message" />;
@@ -665,7 +662,7 @@ class ChannelInner extends PureComponent {
665662

666663
render() {
667664
let core;
668-
const { KeyboardCompatibleView, t } = this.props;
665+
const { children, KeyboardCompatibleView, t } = this.props;
669666
if (this.state.error) {
670667
this.props.logger(
671668
'Channel component',
@@ -693,14 +690,7 @@ class ChannelInner extends PureComponent {
693690
enabled={!this.props.disableKeyboardCompatibleView}
694691
>
695692
<ChannelContext.Provider value={this.getContext()}>
696-
<SuggestionsProvider
697-
handleKeyboardAvoidingViewEnabled={(trueOrFalse) => {
698-
if (this._unmounted) return;
699-
this.setState({ kavEnabled: trueOrFalse });
700-
}}
701-
>
702-
{this.renderComponent()}
703-
</SuggestionsProvider>
693+
<SuggestionsProvider>{children}</SuggestionsProvider>
704694
</ChannelContext.Provider>
705695
</KeyboardCompatibleView>
706696
);

src/components/Chat.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ export const Chat = themed(
165165
this._unmounted = true;
166166
this.props.client.off('connection.recovered');
167167
this.props.client.off('connection.changed');
168-
this.props.client.off(this.handleEvent);
169168
this.unsubscribeNetInfo && this.unsubscribeNetInfo();
170169
}
171170

src/components/KeyboardCompatibleView.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class KeyboardCompatibleView extends React.PureComponent {
4242
super(props);
4343

4444
this.state = {
45-
channelHeight: new Animated.Value('100%'),
45+
channelHeight: new Animated.Value(Dimensions.get('window').height),
4646
// For some reason UI doesn't update sometimes, when state is updated using setValue.
4747
// So to force update the component, I am using following key, which will be incremented
4848
// for every keyboard slide up and down.
@@ -228,8 +228,12 @@ export class KeyboardCompatibleView extends React.PureComponent {
228228
layout: { height },
229229
},
230230
}) => {
231-
// Not to set initial height again.
232-
if (!this.initialHeight) {
231+
// Don't set initial height again if the keyboard is open or initialHeight and layout height are equal
232+
// Helps with issues related to bottom tab bar animations occurring after this initial onLayout call
233+
if (
234+
!this.initialHeight ||
235+
(!this._keyboardOpen && this.initialHeight !== height)
236+
) {
233237
this.initialHeight = height;
234238
this.state.channelHeight.setValue(this.initialHeight);
235239
}

src/components/MessageInput.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ class MessageInput extends PureComponent {
465465
mentioned_users: [],
466466
});
467467
} catch (err) {
468-
console.log('Fialed');
468+
console.log('Failed');
469469
}
470470
}
471471
};

types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// TypeScript Version: 2.8
22

33
import * as React from 'react';
4-
import { Text, GestureResponderEvent, FlatList } from 'react-native';
4+
import { FlatList, GestureResponderEvent } from 'react-native';
55
import * as Client from 'stream-chat';
66
import * as SeamlessImmutable from 'seamless-immutable';
77
import * as i18next from 'i18next';

0 commit comments

Comments
 (0)