├── .gitignore
├── Examples
└── KeyboardAdjustExample.android.js
├── LICENSE
├── README.md
├── android
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── net
│ └── zubricky
│ └── AndroidKeyboardAdjust
│ ├── AndroidKeyboardAdjustModule.java
│ └── AndroidKeyboardAdjustPackage.java
├── index.js
└── package.json
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 |
--------------------------------------------------------------------------------
/Examples/KeyboardAdjustExample.android.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var React = require('react-native');
4 | var {
5 | AppRegistry,
6 | StyleSheet,
7 | Text,
8 | TextInput,
9 | TouchableWithoutFeedback,
10 | View
11 | } = React;
12 |
13 | var dismissKeyboard = require('dismissKeyboard');
14 | var AndroidKeyboardAdjust = require('NativeModules').AndroidKeyboardAdjust;
15 |
16 | var KeyboardAdjustExample = React.createClass({
17 | getInitialState: function() {
18 | return {
19 | setting: 'nothing'
20 | };
21 | },
22 |
23 | setKeyboardSetting: function(setting) {
24 | this.setState({setting: setting});
25 |
26 | switch (setting) {
27 | case 'nothing':
28 | AndroidKeyboardAdjust.setAdjustNothing();
29 | break;
30 | case 'pan':
31 | AndroidKeyboardAdjust.setAdjustPan();
32 | break;
33 | case 'resize':
34 | AndroidKeyboardAdjust.setAdjustResize();
35 | break;
36 | case 'unspecified':
37 | AndroidKeyboardAdjust.setAdjustUnspecified();
38 | break;
39 | }
40 | },
41 |
42 | render: function() {
43 | return (
44 |
45 |
46 | this.setKeyboardSetting('nothing')}>
47 |
48 | Adjust Nothing
49 |
50 |
51 | this.setKeyboardSetting('pan')}>
52 |
53 | Adjust Pan
54 |
55 |
56 |
57 |
58 | this.setKeyboardSetting('resize')}>
59 |
60 | Adjust Resize
61 |
62 |
63 | this.setKeyboardSetting('unspecified')}>
64 |
65 | Adjust Unspecified
66 |
67 |
68 |
69 |
70 | dismissKeyboard()}>
71 |
72 | Hide Keyboard
73 |
74 |
75 |
76 |
77 |
78 |
83 |
84 |
85 | );
86 | }
87 | });
88 |
89 | var styles = StyleSheet.create({
90 | container: {
91 | flex: 1,
92 | backgroundColor: 'red',
93 | borderRadius: 20
94 | },
95 | settingButtons: {
96 | flexDirection: 'row',
97 | margin: 5,
98 | marginBottom: 0
99 | },
100 | settingButton: {
101 | flex: 1,
102 | backgroundColor: 'white',
103 | borderRadius: 5,
104 | margin: 5,
105 | marginBottom: 0
106 | },
107 | settingButtonText: {
108 | textAlign: 'center',
109 | color: 'black',
110 | margin: 10
111 | },
112 | inputBox: {
113 | backgroundColor: 'white',
114 | borderRadius: 5,
115 | margin: 10
116 | },
117 | inputBoxText: {
118 | backgroundColor: 'transparent',
119 | },
120 | });
121 |
122 | AppRegistry.registerComponent('KeyboardAdjustExample', () => KeyboardAdjustExample);
123 |
124 | module.exports = KeyboardAdjustExample;
125 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Marc Zubricky
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # react-native-android-keyboard-adjust
2 |
3 | Change the input mode for the Android keyboard in a React Native app.
4 |
5 | If you are having issues with the default keyboard screen adjust modes and need an easy way to instantly switch them in your app. Quickly go from `Pan` to `Resize` to `Nothing` to get the screen displayed perfectly with the keyboard.
6 |
7 | #### Adjust Nothing Example
8 | 
9 | 
10 |
11 | #### Adjust Resize Example
12 | 
13 | 
14 |
15 | ## Installation instructions for Android
16 |
17 | ### Install the package
18 |
19 | `npm install --save react-native-android-keyboard-adjust`
20 |
21 | ### Update android/app/build.gradle
22 |
23 | Add `compile project(":react-native-android-keyboard-adjust")` to dependencies:
24 |
25 | ```
26 | dependencies {
27 | ...
28 | compile project(":react-native-android-keyboard-adjust")
29 | ...
30 | }
31 | ```
32 | ### Update android/settings.gradle
33 |
34 | ```
35 | ...
36 | include ':react-native-android-keyboard-adjust'
37 | project(':react-native-android-keyboard-adjust').projectDir = new File(settingsDir, '../node_modules/react-native-android-keyboard-adjust/android')
38 | ...
39 | ```
40 |
41 | ### Update MainActivity.java in your project
42 |
43 | Import the package
44 |
45 | ```
46 | import net.zubricky.AndroidKeyboardAdjust.AndroidKeyboardAdjustPackage;
47 | ```
48 |
49 | Add the package to the `getPackages` method
50 |
51 | ```
52 | @Override
53 | protected List getPackages() {
54 | return Arrays.asList(
55 | ...
56 | new AndroidKeyboardAdjustPackage()
57 | );
58 | }
59 | ```
60 |
61 | ## Example
62 | ```
63 | import AndroidKeyboardAdjust from 'react-native-android-keyboard-adjust';
64 |
65 | AndroidKeyboardAdjust.setAdjustNothing();
66 | AndroidKeyboardAdjust.setAdjustPan();
67 | AndroidKeyboardAdjust.setAdjustResize();
68 | AndroidKeyboardAdjust.setAdjustUnspecified();
69 | AndroidKeyboardAdjust.setAlwaysVisible();
70 | AndroidKeyboardAdjust.setAlwaysHidden();
71 | AndroidKeyboardAdjust.setVisible();
72 | AndroidKeyboardAdjust.setHidden();
73 | AndroidKeyboardAdjust.setUnchanged();
74 | ```
75 |
--------------------------------------------------------------------------------
/android/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | jcenter()
4 | }
5 |
6 | dependencies {
7 | classpath 'com.android.tools.build:gradle:2.3.3'
8 | }
9 | }
10 |
11 | apply plugin: 'com.android.library'
12 |
13 | def safeExtGet(prop, fallback) {
14 | rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
15 | }
16 |
17 | android {
18 | compileSdkVersion safeExtGet('compileSdkVersion', 25)
19 | buildToolsVersion safeExtGet('buildToolsVersion', '25.0.3')
20 |
21 | defaultConfig {
22 | minSdkVersion safeExtGet('minSdkVersion', 16)
23 | targetSdkVersion safeExtGet('targetSdkVersion', 25)
24 | versionCode 1
25 | versionName "1.0"
26 | }
27 | lintOptions {
28 | abortOnError false
29 | warning 'InvalidPackage'
30 | }
31 | }
32 |
33 | repositories {
34 | mavenCentral()
35 | }
36 |
37 | dependencies {
38 | compile "com.facebook.react:react-native:+"
39 | }
40 |
--------------------------------------------------------------------------------
/android/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/android/src/main/java/net/zubricky/AndroidKeyboardAdjust/AndroidKeyboardAdjustModule.java:
--------------------------------------------------------------------------------
1 | package net.zubricky.AndroidKeyboardAdjust;
2 |
3 | import android.app.Activity;
4 | import android.view.WindowManager;
5 |
6 | import com.facebook.react.bridge.ReactApplicationContext;
7 | import com.facebook.react.bridge.ReactContextBaseJavaModule;
8 | import com.facebook.react.bridge.ReactMethod;
9 |
10 | /**
11 | * A module to change how the android keyboard is displayed
12 | */
13 | public class AndroidKeyboardAdjustModule extends ReactContextBaseJavaModule {
14 |
15 | public AndroidKeyboardAdjustModule(ReactApplicationContext reactApplicationContext) {
16 | super(reactApplicationContext);
17 | }
18 |
19 | @Override
20 | public String getName() {
21 | return "AndroidKeyboardAdjust";
22 | }
23 |
24 | @ReactMethod
25 | public void setStateUnspecified() {
26 |
27 | final Activity activity = getCurrentActivity();
28 |
29 | if (activity == null) {
30 | return;
31 | }
32 |
33 | activity.runOnUiThread(new Runnable() {
34 | @Override
35 | public void run() {
36 | activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED);
37 | }
38 | });
39 | }
40 |
41 | @ReactMethod
42 | public void setAdjustNothing() {
43 |
44 | final Activity activity = getCurrentActivity();
45 |
46 | if (activity == null) {
47 | return;
48 | }
49 |
50 | activity.runOnUiThread(new Runnable() {
51 | @Override
52 | public void run() {
53 | activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
54 | }
55 | });
56 | }
57 |
58 | @ReactMethod
59 | public void setAdjustPan() {
60 | final Activity activity = getCurrentActivity();
61 |
62 | if (activity == null) {
63 | return;
64 | }
65 |
66 | activity.runOnUiThread(new Runnable() {
67 | @Override
68 | public void run() {
69 | activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
70 | }
71 | });
72 | }
73 |
74 | @ReactMethod
75 | public void setAdjustResize() {
76 | final Activity activity = getCurrentActivity();
77 |
78 | if (activity == null) {
79 | return;
80 | }
81 |
82 | activity.runOnUiThread(new Runnable() {
83 | @Override
84 | public void run() {
85 | activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
86 | }
87 | });
88 | }
89 |
90 | @ReactMethod
91 | public void setAdjustUnspecified() {
92 | final Activity activity = getCurrentActivity();
93 |
94 | if (activity == null) {
95 | return;
96 | }
97 |
98 | activity.runOnUiThread(new Runnable() {
99 | @Override
100 | public void run() {
101 | activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED);
102 | }
103 | });
104 | }
105 |
106 | @ReactMethod
107 | public void setAlwaysHidden() {
108 | final Activity activity = getCurrentActivity();
109 |
110 | if (activity == null) {
111 | return;
112 | }
113 |
114 | activity.runOnUiThread(new Runnable() {
115 | @Override
116 | public void run() {
117 | activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
118 | }
119 | });
120 | }
121 |
122 | @ReactMethod
123 | public void setAlwaysVisible() {
124 | final Activity activity = getCurrentActivity();
125 |
126 | if (activity == null) {
127 | return;
128 | }
129 |
130 | activity.runOnUiThread(new Runnable() {
131 | @Override
132 | public void run() {
133 | activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
134 | }
135 | });
136 | }
137 |
138 | @ReactMethod
139 | public void setVisible() {
140 | final Activity activity = getCurrentActivity();
141 |
142 | if (activity == null) {
143 | return;
144 | }
145 |
146 | activity.runOnUiThread(new Runnable() {
147 | @Override
148 | public void run() {
149 | activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
150 | }
151 | });
152 | }
153 |
154 | @ReactMethod
155 | public void setHidden() {
156 | final Activity activity = getCurrentActivity();
157 |
158 | if (activity == null) {
159 | return;
160 | }
161 |
162 | activity.runOnUiThread(new Runnable() {
163 | @Override
164 | public void run() {
165 | activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
166 | }
167 | });
168 | }
169 |
170 | @ReactMethod
171 | public void setUnchanged() {
172 | final Activity activity = getCurrentActivity();
173 |
174 | if (activity == null) {
175 | return;
176 | }
177 |
178 | activity.runOnUiThread(new Runnable() {
179 | @Override
180 | public void run() {
181 | activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED);
182 | }
183 | });
184 | }
185 | }
186 |
--------------------------------------------------------------------------------
/android/src/main/java/net/zubricky/AndroidKeyboardAdjust/AndroidKeyboardAdjustPackage.java:
--------------------------------------------------------------------------------
1 | package net.zubricky.AndroidKeyboardAdjust;
2 |
3 | import android.app.Activity;
4 |
5 | import com.facebook.react.ReactPackage;
6 | import com.facebook.react.bridge.NativeModule;
7 | import com.facebook.react.bridge.ReactApplicationContext;
8 | import com.facebook.react.uimanager.ViewManager;
9 |
10 | import java.util.Arrays;
11 | import java.util.Collections;
12 | import java.util.List;
13 |
14 | public class AndroidKeyboardAdjustPackage implements ReactPackage {
15 |
16 | public AndroidKeyboardAdjustPackage() {
17 | }
18 |
19 | @Override
20 | public List createNativeModules(ReactApplicationContext reactApplicationContext) {
21 | return Collections.singletonList(new AndroidKeyboardAdjustModule(reactApplicationContext));
22 | }
23 |
24 | @Override
25 | public List createViewManagers(ReactApplicationContext reactApplicationContext) {
26 | return Arrays.asList();
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | import { NativeModules } from 'react-native';
2 | var AndroidKeyboardAdjust = NativeModules.AndroidKeyboardAdjust;
3 | module.exports = AndroidKeyboardAdjust;
4 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-native-android-keyboard-adjust",
3 | "version": "1.2.0",
4 | "description": "Change the input mode for the Android keyboard in a React Native app.",
5 | "main": "index.js",
6 | "author": "Marc Zubricky ",
7 | "license": "MIT",
8 | "devDependencies": {
9 | "react-native": "^0.29.0"
10 | },
11 | "scripts": {
12 | "test": "echo \"Error: no test specified\" && exit 1"
13 | },
14 | "repository": {
15 | "type": "git",
16 | "url": "git+https://github.com/zubricky/react-native-android-keyboard-adjust.git"
17 | },
18 | "keywords": [
19 | "android",
20 | "keyboard",
21 | "react",
22 | "native",
23 | "activity",
24 | "input"
25 | ],
26 | "bugs": {
27 | "url": "https://github.com/zubricky/react-native-android-keyboard-adjust/issues"
28 | },
29 | "homepage": "https://github.com/zubricky/react-native-android-keyboard-adjust#readme"
30 | }
31 |
--------------------------------------------------------------------------------