├── .gitignore
├── Examples
└── KeyboardAdjustExample.android.js
├── 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 |
--------------------------------------------------------------------------------
/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:1.2.3'
8 | }
9 | }
10 |
11 | apply plugin: 'com.android.library'
12 |
13 | android {
14 | compileSdkVersion 23
15 | buildToolsVersion "23.0.1"
16 |
17 | defaultConfig {
18 | minSdkVersion 16
19 | targetSdkVersion 22
20 | versionCode 1
21 | versionName "1.0"
22 | }
23 | lintOptions {
24 | abortOnError false
25 | warning 'InvalidPackage'
26 | }
27 | }
28 |
29 | repositories {
30 | mavenCentral()
31 | }
32 |
33 | dependencies {
34 | compile "com.facebook.react:react-native:0.20.+"
35 | }
36 |
--------------------------------------------------------------------------------
/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 setAdjustNothing() {
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_ADJUST_NOTHING);
37 | }
38 | });
39 | }
40 |
41 | @ReactMethod
42 | public void setAdjustPan() {
43 | final Activity activity = getCurrentActivity();
44 |
45 | if (activity == null) {
46 | return;
47 | }
48 |
49 | activity.runOnUiThread(new Runnable() {
50 | @Override
51 | public void run() {
52 | activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
53 | }
54 | });
55 | }
56 |
57 | @ReactMethod
58 | public void setAdjustResize() {
59 | final Activity activity = getCurrentActivity();
60 |
61 | if (activity == null) {
62 | return;
63 | }
64 |
65 | activity.runOnUiThread(new Runnable() {
66 | @Override
67 | public void run() {
68 | activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
69 | }
70 | });
71 | }
72 |
73 | @ReactMethod
74 | public void setAdjustUnspecified() {
75 | final Activity activity = getCurrentActivity();
76 |
77 | if (activity == null) {
78 | return;
79 | }
80 |
81 | activity.runOnUiThread(new Runnable() {
82 | @Override
83 | public void run() {
84 | activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED);
85 | }
86 | });
87 | }
88 |
89 | @ReactMethod
90 | public void setAlwaysHidden() {
91 | final Activity activity = getCurrentActivity();
92 |
93 | if (activity == null) {
94 | return;
95 | }
96 |
97 | activity.runOnUiThread(new Runnable() {
98 | @Override
99 | public void run() {
100 | activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
101 | }
102 | });
103 | }
104 |
105 | @ReactMethod
106 | public void setAlwaysVisible() {
107 | final Activity activity = getCurrentActivity();
108 |
109 | if (activity == null) {
110 | return;
111 | }
112 |
113 | activity.runOnUiThread(new Runnable() {
114 | @Override
115 | public void run() {
116 | activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
117 | }
118 | });
119 | }
120 |
121 | @ReactMethod
122 | public void setVisible() {
123 | final Activity activity = getCurrentActivity();
124 |
125 | if (activity == null) {
126 | return;
127 | }
128 |
129 | activity.runOnUiThread(new Runnable() {
130 | @Override
131 | public void run() {
132 | activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
133 | }
134 | });
135 | }
136 |
137 | @ReactMethod
138 | public void setHidden() {
139 | final Activity activity = getCurrentActivity();
140 |
141 | if (activity == null) {
142 | return;
143 | }
144 |
145 | activity.runOnUiThread(new Runnable() {
146 | @Override
147 | public void run() {
148 | activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
149 | }
150 | });
151 | }
152 |
153 | @ReactMethod
154 | public void setUnchanged() {
155 | final Activity activity = getCurrentActivity();
156 |
157 | if (activity == null) {
158 | return;
159 | }
160 |
161 | activity.runOnUiThread(new Runnable() {
162 | @Override
163 | public void run() {
164 | activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED);
165 | }
166 | });
167 | }
168 | }
169 |
--------------------------------------------------------------------------------
/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.JavaScriptModule;
7 | import com.facebook.react.bridge.NativeModule;
8 | import com.facebook.react.bridge.ReactApplicationContext;
9 | import com.facebook.react.uimanager.ViewManager;
10 |
11 | import java.util.Arrays;
12 | import java.util.Collections;
13 | import java.util.List;
14 |
15 | public class AndroidKeyboardAdjustPackage implements ReactPackage {
16 |
17 | public AndroidKeyboardAdjustPackage() {
18 |
19 | }
20 |
21 | @Override
22 | public List createNativeModules(ReactApplicationContext reactApplicationContext) {
23 | return Collections.singletonList(new AndroidKeyboardAdjustModule(reactApplicationContext));
24 | }
25 |
26 | @Override
27 | public List> createJSModules() {
28 | return Collections.emptyList();
29 | }
30 |
31 | @Override
32 | public List createViewManagers(ReactApplicationContext reactApplicationContext) {
33 | return Arrays.asList();
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/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": "0.1.4",
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.19.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 |
--------------------------------------------------------------------------------