Skip to content

Commit

Permalink
Merge pull request #6 from jr-k/master
Browse files Browse the repository at this point in the history
Compatibility react 0.29.0
  • Loading branch information
zubricky authored Mar 11, 2017
2 parents 834dbd0 + d2c5d57 commit f5840da
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Add the package to the `getPackages` method
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
...
new AndroidKeyboardAdjustPackage(this)
new AndroidKeyboardAdjustPackage()
);
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@
*/
public class AndroidKeyboardAdjustModule extends ReactContextBaseJavaModule {

private Activity activity;

public AndroidKeyboardAdjustModule(ReactApplicationContext reactApplicationContext, Activity activity) {
public AndroidKeyboardAdjustModule(ReactApplicationContext reactApplicationContext) {
super(reactApplicationContext);
this.activity = activity;
}

@Override
Expand All @@ -26,90 +23,145 @@ public String getName() {

@ReactMethod
public void setAdjustNothing() {
this.activity.runOnUiThread(new Runnable() {

final Activity activity = getCurrentActivity();

if (activity == null) {
return;
}

activity.runOnUiThread(new Runnable() {
@Override
public void run() {
AndroidKeyboardAdjustModule.this.activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
}
});
}

@ReactMethod
public void setAdjustPan() {
this.activity.runOnUiThread(new Runnable() {
final Activity activity = getCurrentActivity();

if (activity == null) {
return;
}

activity.runOnUiThread(new Runnable() {
@Override
public void run() {
AndroidKeyboardAdjustModule.this.activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
}
});
}

@ReactMethod
public void setAdjustResize() {
this.activity.runOnUiThread(new Runnable() {
final Activity activity = getCurrentActivity();

if (activity == null) {
return;
}

activity.runOnUiThread(new Runnable() {
@Override
public void run() {
AndroidKeyboardAdjustModule.this.activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
}
});
}

@ReactMethod
public void setAdjustUnspecified() {
this.activity.runOnUiThread(new Runnable() {
final Activity activity = getCurrentActivity();

if (activity == null) {
return;
}

activity.runOnUiThread(new Runnable() {
@Override
public void run() {
AndroidKeyboardAdjustModule.this.activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED);
activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED);
}
});
}

@ReactMethod
public void setAlwaysHidden() {
this.activity.runOnUiThread(new Runnable() {
final Activity activity = getCurrentActivity();

if (activity == null) {
return;
}

activity.runOnUiThread(new Runnable() {
@Override
public void run() {
AndroidKeyboardAdjustModule.this.activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}
});
}

@ReactMethod
public void setAlwaysVisible() {
this.activity.runOnUiThread(new Runnable() {
final Activity activity = getCurrentActivity();

if (activity == null) {
return;
}

activity.runOnUiThread(new Runnable() {
@Override
public void run() {
AndroidKeyboardAdjustModule.this.activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
});
}

@ReactMethod
public void setVisible() {
this.activity.runOnUiThread(new Runnable() {
final Activity activity = getCurrentActivity();

if (activity == null) {
return;
}

activity.runOnUiThread(new Runnable() {
@Override
public void run() {
AndroidKeyboardAdjustModule.this.activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
}
});
}

@ReactMethod
public void setHidden() {
this.activity.runOnUiThread(new Runnable() {
final Activity activity = getCurrentActivity();

if (activity == null) {
return;
}

activity.runOnUiThread(new Runnable() {
@Override
public void run() {
AndroidKeyboardAdjustModule.this.activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
}
});
}

@ReactMethod
public void setUnchanged() {
this.activity.runOnUiThread(new Runnable() {
final Activity activity = getCurrentActivity();

if (activity == null) {
return;
}

activity.runOnUiThread(new Runnable() {
@Override
public void run() {
AndroidKeyboardAdjustModule.this.activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED);
activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@

public class AndroidKeyboardAdjustPackage implements ReactPackage {

private Activity mActivity = null;

public AndroidKeyboardAdjustPackage(Activity activity) {
mActivity = activity;
public AndroidKeyboardAdjustPackage() {

}

@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactApplicationContext) {
return Collections.<NativeModule>singletonList(new AndroidKeyboardAdjustModule(reactApplicationContext, mActivity));
return Collections.<NativeModule>singletonList(new AndroidKeyboardAdjustModule(reactApplicationContext));
}

@Override
Expand Down
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
var AndroidKeyboardAdjust = require('NativeModules').AndroidKeyboardAdjust;
module.exports = AndroidKeyboardAdjust;
import { NativeModules } from 'react-native';
var AndroidKeyboardAdjust = NativeModules.AndroidKeyboardAdjust;
module.exports = AndroidKeyboardAdjust;

0 comments on commit f5840da

Please sign in to comment.