Skip to content

Commit b48b6d1

Browse files
authored
feat: add web view API to hide input accessory views (#14390)
* feat: add web view API to hide input accessory views * feat(ios): add autoAdjustScrollViewInsets API
1 parent 58a5d59 commit b48b6d1

File tree

5 files changed

+97
-1
lines changed

5 files changed

+97
-1
lines changed

apidoc/Titanium/UI/WebView.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,36 @@ properties:
907907
platforms: [iphone, ipad, macos]
908908
since: {iphone: "6.1.0", ipad: "6.1.0", macos: "9.2.0"}
909909

910+
- name: hideKeyboardAccessoryView
911+
summary: A Boolean value indicating whether to hide the keyboard accessory bar.
912+
description: |
913+
When this property is set to `true`, the keyboard accessory bar (the bar with "Previous",
914+
"Next" and "Done" buttons that appears above the keyboard when focusing input fields in
915+
web content) is hidden. This can be useful when you want to provide your own custom
916+
input accessory or simply want a cleaner keyboard appearance.
917+
918+
Set to `false` (the default) to show the standard keyboard accessory bar.
919+
type: Boolean
920+
default: false
921+
platforms: [iphone, ipad, macos]
922+
since: {iphone: "13.2.0", ipad: "13.2.0", macos: "13.2.0"}
923+
924+
- name: autoAdjustScrollViewInsets
925+
summary: |
926+
Specifies whether or not the web view should automatically adjust its scroll view insets.
927+
description: |
928+
When the value is `true`, it allows the web view to adjust its scroll view insets in response
929+
to the screen areas consumed by the status bar, navigation bar, toolbar and tab bar (safe areas).
930+
931+
This is useful when displaying a web view that extends under navigation bars or into
932+
safe area regions, ensuring content is not obscured.
933+
934+
The default behavior assumes that this is `false`.
935+
type: Boolean
936+
default: false
937+
platforms: [iphone, ipad, macos]
938+
since: {iphone: "13.2.0", ipad: "13.2.0", macos: "13.2.0"}
939+
910940
- name: ignoreSslError
911941
summary: Controls whether to ignore invalid SSL certificates or not.
912942
description: |

iphone/Classes/TiUIWebView.m

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#import "TiUIWebViewProxy.h"
1111
#import "TiUIiOSWebViewConfigurationProxy.h"
1212
#import "TiUIiOSWebViewDecisionHandlerProxy.h"
13+
#import "TiWebView.h"
1314

1415
#import <TitaniumKit/Mimetypes.h>
1516
#import <TitaniumKit/SBJSON.h>
@@ -82,7 +83,7 @@ - (WKWebView *)webView
8283

8384
_willHandleTouches = [TiUtils boolValue:[[self proxy] valueForKey:@"willHandleTouches"] def:YES];
8485

85-
_webView = [[WKWebView alloc] initWithFrame:[self bounds] configuration:config];
86+
_webView = [[TiWebView alloc] initWithFrame:[self bounds] configuration:config];
8687
#if TARGET_OS_SIMULATOR && __IPHONE_OS_VERSION_MAX_ALLOWED >= 160400
8788
if (@available(iOS 16.4, *)) {
8889
_webView.inspectable = YES;
@@ -389,6 +390,27 @@ - (void)setKeyboardDisplayRequiresUserAction_:(id)value
389390
[[self proxy] replaceValue:value forKey:@"keyboardDisplayRequiresUserAction" notification:NO];
390391
}
391392

393+
- (void)setHideKeyboardAccessoryView_:(id)value
394+
{
395+
ENSURE_TYPE(value, NSNumber);
396+
397+
[[self proxy] replaceValue:value forKey:@"hideKeyboardAccessoryView" notification:NO];
398+
[[self webView] setHideInputAccessoryView:[TiUtils boolValue:value def:NO]];
399+
}
400+
401+
- (void)setAutoAdjustScrollViewInsets_:(id)value
402+
{
403+
ENSURE_TYPE(value, NSNumber);
404+
405+
[[self proxy] replaceValue:value forKey:@"autoAdjustScrollViewInsets" notification:NO];
406+
407+
if ([TiUtils boolValue:value def:NO]) {
408+
[[[self webView] scrollView] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentAlways];
409+
} else {
410+
[[[self webView] scrollView] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
411+
}
412+
}
413+
392414
- (void)reload
393415
{
394416
if (_webView == nil) {

iphone/Classes/TiWebView.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// TiWebView.h
3+
// Titanium
4+
//
5+
// Created by Hans Knöchel on 02.02.26.
6+
//
7+
8+
#import <WebKit/WebKit.h>
9+
10+
NS_ASSUME_NONNULL_BEGIN
11+
12+
@interface TiWebView : WKWebView
13+
14+
@property (nonatomic, assign) BOOL hideInputAccessoryView;
15+
16+
@end
17+
18+
NS_ASSUME_NONNULL_END

iphone/Classes/TiWebView.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// TiWebView.m
3+
// Titanium
4+
//
5+
// Created by Hans Knöchel on 02.02.26.
6+
//
7+
8+
#import "TiWebView.h"
9+
10+
@implementation TiWebView
11+
12+
- (__kindof UIView *)inputAccessoryView
13+
{
14+
if (self.hideInputAccessoryView) {
15+
return nil;
16+
}
17+
return [super inputAccessoryView];
18+
}
19+
20+
@end

iphone/iphone/Titanium.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
3A0E54371BE811CD003EE654 /* TiUIiOSMenuPopupProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A0E54361BE811CD003EE654 /* TiUIiOSMenuPopupProxy.m */; };
160160
3A1E40511BEAC73D00943233 /* TiUIiOSMenuPopup.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A1E40501BEAC73D00943233 /* TiUIiOSMenuPopup.m */; };
161161
3A275F3E1BA881B300EC4912 /* TiUIActivityIndicatorStyleProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A275F3D1BA881B300EC4912 /* TiUIActivityIndicatorStyleProxy.m */; };
162+
3A2BC6332F30D81400D4CBD4 /* TiWebView.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A2BC6322F30D81400D4CBD4 /* TiWebView.m */; };
162163
3A320F992B6EDC7600009E90 /* TiSymbolEffectManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A320F982B6EDC7600009E90 /* TiSymbolEffectManager.m */; };
163164
3A38F30424D6EBBD00CC6EFB /* TiUtils+Addons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A38F30324D6EBBD00CC6EFB /* TiUtils+Addons.swift */; };
164165
3A3BBAF51D3E2F0F008450DF /* TiAppiOSUserNotificationCenterProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A3BBAF41D3E2F0F008450DF /* TiAppiOSUserNotificationCenterProxy.m */; };
@@ -606,6 +607,8 @@
606607
3A1E40501BEAC73D00943233 /* TiUIiOSMenuPopup.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TiUIiOSMenuPopup.m; sourceTree = "<group>"; };
607608
3A275F3C1BA881B300EC4912 /* TiUIActivityIndicatorStyleProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TiUIActivityIndicatorStyleProxy.h; sourceTree = "<group>"; };
608609
3A275F3D1BA881B300EC4912 /* TiUIActivityIndicatorStyleProxy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TiUIActivityIndicatorStyleProxy.m; sourceTree = "<group>"; };
610+
3A2BC6312F30D81400D4CBD4 /* TiWebView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TiWebView.h; sourceTree = "<group>"; };
611+
3A2BC6322F30D81400D4CBD4 /* TiWebView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TiWebView.m; sourceTree = "<group>"; };
609612
3A320F972B6EDC7600009E90 /* TiSymbolEffectManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TiSymbolEffectManager.h; sourceTree = "<group>"; };
610613
3A320F982B6EDC7600009E90 /* TiSymbolEffectManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TiSymbolEffectManager.m; sourceTree = "<group>"; };
611614
3A38F30324D6EBBD00CC6EFB /* TiUtils+Addons.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TiUtils+Addons.swift"; sourceTree = "<group>"; };
@@ -1321,6 +1324,8 @@
13211324
24EB02BF111BF827001DC2D1 /* TiUIWebView.h */,
13221325
24EB02C0111BF827001DC2D1 /* TiUIWebView.m */,
13231326
24EB06EC111D03F9001DC2D1 /* bridge.txt */,
1327+
3A2BC6312F30D81400D4CBD4 /* TiWebView.h */,
1328+
3A2BC6322F30D81400D4CBD4 /* TiWebView.m */,
13241329
);
13251330
name = Webview;
13261331
sourceTree = "<group>";
@@ -2163,6 +2168,7 @@
21632168
1923696620E48D4300567508 /* TiUIiOSWebViewProcessPoolProxy.m in Sources */,
21642169
DBF4B13B200FD93400777136 /* TiUIApplicationShortcutsProxy.m in Sources */,
21652170
24CA8B85111161FE0084E2DE /* TiUITabGroupProxy.m in Sources */,
2171+
3A2BC6332F30D81400D4CBD4 /* TiWebView.m in Sources */,
21662172
24CA8B8C111161FE0084E2DE /* TiUISwitchProxy.m in Sources */,
21672173
24CA8B8D111161FE0084E2DE /* TiUISwitch.m in Sources */,
21682174
24CA8B8F111161FE0084E2DE /* TiUISliderProxy.m in Sources */,

0 commit comments

Comments
 (0)