├── .npmignore ├── LICENSE ├── README.md ├── android ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── io │ │ └── github │ │ └── mr03web │ │ └── softinputmode │ │ ├── SoftInputModeModule.java │ │ └── SoftInputModePackage.java │ └── res │ └── values │ └── strings.xml ├── index.d.ts ├── index.js └── package.json /.npmignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .gradle 3 | /build 4 | gradle/ 5 | gradlew 6 | gradlew.bat 7 | local.properties -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 MR03web 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-set-soft-input-mode 2 | 3 | setSoftInputMode on Android. 4 | 5 | ## Installation 6 | 7 | ### Download 8 | 9 | Run `npm i react-native-set-soft-input-mode --save` 10 | Or 11 | Run `yarn add react-native-set-soft-input-mode` 12 | 13 | ### Plugin Installation 14 | 15 | step-1. In your android/settings.gradle file, make the following additions: 16 | 17 | ```java 18 | include ':react-native-set-soft-input-mode' 19 | project(':react-native-set-soft-input-mode').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-set-soft-input-mode/android') 20 | ``` 21 | 22 | step-2. In your android/app/build.gradle file, add the `:react-native-set-soft-input-mode` project as a compile-time dependency: 23 | 24 | ```java 25 | ... 26 | dependencies { 27 | ... 28 | implementation project(':react-native-set-soft-input-mode') 29 | } 30 | ``` 31 | 32 | step-3. Update the MainApplication.java file to use `react-native-set-soft-input-mode` via the following changes: 33 | 34 | ```java 35 | import io.github.mr03web.softinputmode.SoftInputModePackage; 36 | 37 | public class MainApplication extends Application implements ReactApplication { 38 | 39 | private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { 40 | @Override 41 | protected boolean getUseDeveloperSupport() { 42 | return BuildConfig.DEBUG; 43 | } 44 | 45 | @Override 46 | protected List getPackages() { 47 | return Arrays.asList( 48 | new MainReactPackage(), 49 | new SoftInputModePackage() // here 50 | ); 51 | } 52 | }; 53 | 54 | ... 55 | } 56 | ``` 57 | 58 | ## Usage 59 | 60 | Import `react-native-set-soft-input-mode` in your JS file. 61 | 62 | Use like so: 63 | 64 | ```javascript 65 | import SoftInputMode from "react-native-set-soft-input-mode"; 66 | 67 | export default class Page extends Component { 68 | componentDidMount() { 69 | SoftInputMode.set(SoftInputMode.ADJUST_NOTHING); 70 | } 71 | } 72 | ``` 73 | 74 | ## Options 75 | 76 | | Name | Description | 77 | | ------------------ | ----------------------------- | 78 | | ADJUST_NOTHING | SOFT_INPUT_ADJUST_NOTHING | 79 | | ADJUST_PAN | SOFT_INPUT_ADJUST_PAN | 80 | | ADJUST_RESIZE | SOFT_INPUT_ADJUST_RESIZE | 81 | | ADJUST_UNSPECIFIED | SOFT_INPUT_ADJUST_UNSPECIFIED | 82 | -------------------------------------------------------------------------------- /android/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion = 28 5 | buildToolsVersion = "28.0.3" 6 | 7 | defaultConfig { 8 | minSdkVersion 16 9 | targetSdkVersion 28 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(dir: "libs", include: ["*.jar"]) 23 | implementation 'com.android.support:appcompat-v7:28.0.0' 24 | implementation "com.facebook.react:react-native:+" // From node_modules 25 | } 26 | -------------------------------------------------------------------------------- /android/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Users\Administrator\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /android/src/main/java/io/github/mr03web/softinputmode/SoftInputModeModule.java: -------------------------------------------------------------------------------- 1 | package io.github.mr03web.softinputmode; 2 | 3 | import android.app.Activity; 4 | import android.os.Handler; 5 | import android.os.Message; 6 | import android.view.WindowManager; 7 | 8 | import com.facebook.react.bridge.ReactApplicationContext; 9 | import com.facebook.react.bridge.ReactContextBaseJavaModule; 10 | import com.facebook.react.bridge.ReactMethod; 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | import javax.annotation.Nullable; 16 | 17 | /** 18 | * Created by Administrator on 2018/1/4. 19 | */ 20 | 21 | public class SoftInputModeModule extends ReactContextBaseJavaModule { 22 | 23 | 24 | private static final String SOFT_INPUT_ADJUST_NOTHING = "ADJUST_NOTHING"; 25 | private static final String SOFT_INPUT_ADJUST_PAN = "ADJUST_PAN"; 26 | private static final String SOFT_INPUT_ADJUST_RESIZE = "ADJUST_RESIZE"; 27 | private static final String SOFT_INPUT_ADJUST_UNSPECIFIED = "ADJUST_UNSPECIFIED"; 28 | 29 | public SoftInputModeModule(ReactApplicationContext reactContext) { 30 | super(reactContext); 31 | } 32 | 33 | @Override 34 | public String getName() { 35 | return "SoftInputMode"; 36 | } 37 | 38 | private Handler mHandler = new Handler(getReactApplicationContext().getMainLooper()){ 39 | @Override 40 | public void handleMessage(Message msg) { 41 | super.handleMessage(msg); 42 | Activity activity = getCurrentActivity(); 43 | if (activity != null) { // check activity 44 | activity.getWindow().setSoftInputMode(msg.what); 45 | } 46 | } 47 | }; 48 | 49 | @Nullable 50 | @Override 51 | public Map getConstants() { 52 | final Map constants = new HashMap<>(); 53 | constants.put(SOFT_INPUT_ADJUST_NOTHING, WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING); 54 | constants.put(SOFT_INPUT_ADJUST_PAN, WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); 55 | constants.put(SOFT_INPUT_ADJUST_RESIZE, WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); 56 | constants.put(SOFT_INPUT_ADJUST_UNSPECIFIED, WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED); 57 | return constants; 58 | } 59 | 60 | @ReactMethod 61 | public void set(int type) { 62 | Message msg = Message.obtain(); 63 | msg.what = type; 64 | mHandler.sendMessageDelayed(msg, 0); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /android/src/main/java/io/github/mr03web/softinputmode/SoftInputModePackage.java: -------------------------------------------------------------------------------- 1 | package io.github.mr03web.softinputmode; 2 | 3 | import com.facebook.react.ReactPackage; 4 | import com.facebook.react.bridge.JavaScriptModule; 5 | import com.facebook.react.bridge.NativeModule; 6 | import com.facebook.react.bridge.ReactApplicationContext; 7 | import com.facebook.react.uimanager.ViewManager; 8 | 9 | import java.util.ArrayList; 10 | import java.util.Collections; 11 | import java.util.List; 12 | 13 | /** 14 | * Created by Administrator on 2018/1/4. 15 | */ 16 | 17 | public class SoftInputModePackage implements ReactPackage { 18 | 19 | @Override 20 | public List createNativeModules(ReactApplicationContext reactContext) { 21 | List modules = new ArrayList<>(); 22 | modules.add(new SoftInputModeModule(reactContext)); 23 | return modules; 24 | } 25 | 26 | @Override 27 | public List createViewManagers(ReactApplicationContext reactContext) { 28 | return Collections.emptyList(); 29 | } 30 | 31 | // Deprecated RN 0.47 32 | public List> createJSModules() { 33 | return Collections.emptyList(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /android/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | SoftInputMode 3 | 4 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | declare module "react-native-set-soft-input-mode" { 2 | const SoftInputMode: { 3 | set: (value: number) => void; 4 | ADJUST_NOTHING: number; 5 | ADJUST_PAN: number; 6 | ADJUST_RESIZE: number; 7 | ADJUST_UNSPECIFIED: number; 8 | }; 9 | export default SoftInputMode; 10 | } 11 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * SoftInputMode 3 | */ 4 | 5 | import { NativeModules } from 'react-native'; 6 | 7 | export default NativeModules.SoftInputMode; 8 | 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-set-soft-input-mode", 3 | "version": "1.1.0", 4 | "description": "setSoftInputMode on Android", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/MR03web/react-native-set-soft-input-mode.git" 12 | }, 13 | "keywords": [ 14 | "react-native", 15 | "react-native-component", 16 | "react-native-set-soft-input-mode", 17 | "setSoftInputMode", 18 | "SoftInputMode", 19 | "android" 20 | ], 21 | "types": "index.d.ts", 22 | "author": "MR03web", 23 | "license": "MIT", 24 | "bugs": { 25 | "url": "https://github.com/MR03web/react-native-set-soft-input-mode/issues" 26 | }, 27 | "homepage": "https://github.com/MR03web/react-native-set-soft-input-mode#readme" 28 | } 29 | --------------------------------------------------------------------------------