Skip to content

Commit

Permalink
revert last commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mendyEdri committed Jun 29, 2020
1 parent 4a0d6f7 commit 4c55304
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 63 deletions.
9 changes: 6 additions & 3 deletions demo/demoScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,14 @@ export default class KeyboardInput extends Component {
});
}

safeAreaSwitchToggle = () => {
safeAreaSwitchToggleForIOS = () => {
if (Platform.OS !== 'ios') {
return (<View />);
}
const {useSafeArea} = this.state;
return (
<View style={styles.safeAreaSwitchContainer}>
<Text>(iOS) Safe Area Enabled:</Text>
<Text>Safe Area Enabled:</Text>
<Switch style={styles.switch} value={useSafeArea} onValueChange={this.toggleUseSafeArea}/>
</View>
);
Expand All @@ -120,7 +123,7 @@ export default class KeyboardInput extends Component {
<Text>Action</Text>
</TouchableOpacity>
</View>
{ this.safeAreaSwitchToggle() }
{ this.safeAreaSwitchToggleForIOS() }
<View style={{flexDirection: 'row'}}>
{
this.getToolbarButtons().map((button, index) =>
Expand Down
11 changes: 3 additions & 8 deletions lib/ios/RCTCustomInputController/RCTCustomInputController.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ @interface RCTCustomInputController () <_WXInputHelperViewDelegate> {
}

@property (nonatomic) BOOL customInputComponentPresented;
@property (nonatomic, strong) RCTCustomKeyboardViewController* customKeyboardController;
@end

@implementation RCTCustomInputController
Expand Down Expand Up @@ -118,10 +117,6 @@ - (BOOL)shouldUseSafeAreaFrom:(NSDictionary *)params {
return [params[@"useSafeArea"] isEqual:@(1)];
}

RCT_EXPORT_METHOD(updateSafeArea:(BOOL)useSafeArea) {
[self.customKeyboardController setNeedSafeAreaUpdate:useSafeArea];
}

RCT_EXPORT_METHOD(presentCustomInputComponent:(nonnull NSNumber*)inputFieldTag params:(nonnull NSDictionary*)params)
{
RCTBridge* bridge = [self.bridge valueForKey:@"parentBridge"];
Expand All @@ -145,8 +140,8 @@ - (BOOL)shouldUseSafeAreaFrom:(NSDictionary *)params {
self.customInputComponentPresented = NO;

BOOL useSafeArea = [self shouldUseSafeAreaFrom:params];
self.customKeyboardController = [[RCTCustomKeyboardViewController alloc] initWithUsingSafeArea:useSafeArea];
self.customKeyboardController.rootView = rv;
RCTCustomKeyboardViewController* customKeyboardController = [[RCTCustomKeyboardViewController alloc] initWithUsingSafeArea:useSafeArea];
customKeyboardController.rootView = rv;

_WXInputHelperView* helperView = [[_WXInputHelperView alloc] initWithFrame:CGRectZero];
helperView.tag = kHlperViewTag;
Expand Down Expand Up @@ -200,7 +195,7 @@ - (BOOL)shouldUseSafeAreaFrom:(NSDictionary *)params {
[inputField.superview addSubview:helperView];
[inputField.superview sendSubviewToBack:helperView];

helperView.inputViewController = self.customKeyboardController;
helperView.inputViewController = customKeyboardController;
[helperView reloadInputViews];
[helperView becomeFirstResponder];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

- (instancetype)initWithUsingSafeArea:(BOOL)useSafeArea;
- (void) setAllowsSelfSizing:(BOOL)allowsSelfSizing;
- (void)setNeedSafeAreaUpdate:(BOOL)useSafeArea;

@property (nonatomic, strong) NSLayoutConstraint *heightConstraint;
@property (nonatomic, strong) RCTRootView *rootView;
Expand Down
53 changes: 8 additions & 45 deletions lib/ios/RCTCustomInputController/RCTCustomKeyboardViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

@interface RCTCustomKeyboardViewController ()
@property (nonatomic, assign, getter=isUsingSafeArea) BOOL useSafeArea;
@property (nonatomic, strong) NSLayoutConstraint *bottomConstraintToSafeArea;
@property (nonatomic, strong) NSLayoutConstraint *bottomConstraintToView;
@end

@implementation RCTCustomKeyboardViewController
Expand Down Expand Up @@ -70,66 +68,31 @@ -(void)setRootView:(RCTRootView*)rootView
_rootView.translatesAutoresizingMaskIntoConstraints = NO;
[self.inputView addSubview:_rootView];

[self updateRootViewConstraints: self.isUsingSafeArea];
[self updateRootViewConstraints];
[self.inputView setNeedsLayout];
}

- (void)setNeedSafeAreaUpdate:(BOOL)useSafeArea {
[self updateBottomConstraint:useSafeArea];
[self.inputView setNeedsLayout];
}

- (void)updateRootViewConstraints:(BOOL)useSafeArea {
- (void)updateRootViewConstraints {
[_rootView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor].active = YES;
[_rootView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor].active = YES;
[_rootView.topAnchor constraintEqualToAnchor:self.view.topAnchor].active = YES;
[self createBottomConstraintsOnce];

[self updateBottomConstraint:useSafeArea];
}

- (void)createBottomConstraintsOnce {
if (self.bottomConstraintToSafeArea && self.bottomConstraintToView) {
return;
}
NSLayoutYAxisAnchor *safeAreaAnchor = [self bottomLayoutAnchorUsingSafeArea:YES];
NSLayoutYAxisAnchor *bottomViewAnchor = [self bottomLayoutAnchorUsingSafeArea:NO];

self.bottomConstraintToSafeArea = [_rootView.bottomAnchor constraintEqualToAnchor:safeAreaAnchor];
self.bottomConstraintToView = [_rootView.bottomAnchor constraintEqualToAnchor:bottomViewAnchor];
}

- (void)updateBottomConstraint:(BOOL)useSafeArea {
if (useSafeArea) {
[self activateSafeAreaConstraint];
} else {
[self activateBottomViewConstraint];
}
}

- (void)activateSafeAreaConstraint {
[self.bottomConstraintToView setActive:NO];
[self.bottomConstraintToSafeArea setActive:YES];
}

- (void)activateBottomViewConstraint {
[self.bottomConstraintToSafeArea setActive:NO];
[self.bottomConstraintToView setActive:YES];
NSLayoutYAxisAnchor *yAxisAnchor = [self bottomLayoutAnchorUsingSafeArea:self.isUsingSafeArea];
[_rootView.bottomAnchor constraintEqualToAnchor:yAxisAnchor].active = YES;
}

- (NSLayoutYAxisAnchor *)bottomLayoutAnchorUsingSafeArea:(BOOL)useSafeArea {
NSLayoutYAxisAnchor *bottomAnchor = self.view.bottomAnchor;
NSLayoutYAxisAnchor *yAxisAnchor = self.view.bottomAnchor;

if (!useSafeArea) {
return bottomAnchor;
return yAxisAnchor;
}

#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_10_3
if (@available(iOS 11.0, *)) {
bottomAnchor = self.view.safeAreaLayoutGuide.bottomAnchor;
yAxisAnchor = self.view.safeAreaLayoutGuide.bottomAnchor;
}
#endif
return bottomAnchor;
return yAxisAnchor;
}

@end
2 changes: 0 additions & 2 deletions src/CustomKeyboardView.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ export default class CustomKeyboardView extends Component {
} else {
TextInputKeyboardManagerIOS.removeInputComponent(inputRef);
}
} else if (IsIOS && useSafeArea !== this.props.useSafeArea) {
TextInputKeyboardManagerIOS.setUsingSafeArea(useSafeArea);
}

if (onRequestShowKeyboard && !this.registeredRequestShowKeyboard) {
Expand Down
4 changes: 0 additions & 4 deletions src/TextInputKeyboardMangerIOS.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ export default class TextInputKeyboardManagerIOS {
}
};

static setUsingSafeArea = (useSafeArea) => {
CustomInputController.updateSafeArea(useSafeArea);
}

static removeInputComponent = (textInputRef) => {
if (!textInputRef || !CustomInputController) {
return;
Expand Down

0 comments on commit 4c55304

Please sign in to comment.