-
Notifications
You must be signed in to change notification settings - Fork 24.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Initial implementation of Modal on Android #5320
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1f0391c
Initial implementation of Modal on Android
satya164 750c7f1
Implement 'transparent' prop for <Modal />
satya164 0f9427e
Add license headers
satya164 e20013e
Fix transparency of modal
satya164 91a55bb
Merge branch 'master' into modal
satya164 a16b731
Dismiss Modal properly
satya164 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
ReactAndroid/src/main/java/com/facebook/react/views/modalhost/DismissEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
package com.facebook.react.views.modalhost; | ||
|
||
import com.facebook.react.uimanager.events.Event; | ||
import com.facebook.react.uimanager.events.RCTEventEmitter; | ||
|
||
/** | ||
* {@link Event} for dismissing a Dialog. | ||
*/ | ||
public class DismissEvent extends Event<DismissEvent> { | ||
|
||
public static final String EVENT_NAME = "topDismiss"; | ||
|
||
protected DismissEvent(int viewTag, long timestampMs) { | ||
super(viewTag, timestampMs); | ||
} | ||
|
||
@Override | ||
public String getEventName() { | ||
return EVENT_NAME; | ||
} | ||
|
||
@Override | ||
public void dispatch(RCTEventEmitter rctEventEmitter) { | ||
rctEventEmitter.receiveEvent(getViewTag(), getEventName(), null); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
ReactAndroid/src/main/java/com/facebook/react/views/modalhost/ReactModalHostManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
package com.facebook.react.views.modalhost; | ||
|
||
import android.content.DialogInterface; | ||
import android.os.SystemClock; | ||
|
||
import com.facebook.react.common.MapBuilder; | ||
import com.facebook.react.uimanager.ThemedReactContext; | ||
import com.facebook.react.uimanager.UIManagerModule; | ||
import com.facebook.react.uimanager.ViewGroupManager; | ||
import com.facebook.react.uimanager.annotations.ReactProp; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* View manager for {@link ReactModalHostView} components. | ||
* | ||
* Emits an {@code onDismiss} event when the Dialog host is dismissed. | ||
*/ | ||
public class ReactModalHostManager extends ViewGroupManager<ReactModalHostView> { | ||
|
||
private static final String REACT_CLASS = "RCTModalHostView"; | ||
|
||
@ReactProp(name = "animated") | ||
public void setAnimated(ReactModalHostView view, boolean animated) { | ||
// TODO(8776300): Implement this | ||
} | ||
|
||
@ReactProp(name = "transparent") | ||
public void setTransparent(ReactModalHostView view, boolean transparent) { | ||
view.setTransparent(transparent); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return REACT_CLASS; | ||
} | ||
|
||
@Override | ||
protected ReactModalHostView createViewInstance(ThemedReactContext reactContext) { | ||
return new ReactModalHostView(reactContext); | ||
} | ||
|
||
@Override | ||
public void onDropViewInstance(ReactModalHostView view) { | ||
super.onDropViewInstance(view); | ||
view.dismissModal(); | ||
} | ||
|
||
@Override | ||
protected void addEventEmitters( | ||
final ThemedReactContext reactContext, | ||
final ReactModalHostView view) { | ||
view.setOnDismissListener( | ||
new DialogInterface.OnDismissListener() { | ||
@Override | ||
public void onDismiss(DialogInterface dialog) { | ||
reactContext.getNativeModule(UIManagerModule.class) | ||
.getEventDispatcher() | ||
.dispatchEvent(new DismissEvent(view.getId(), SystemClock.uptimeMillis())); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public Map<String, Object> getExportedCustomDirectEventTypeConstants() { | ||
return MapBuilder.<String, Object>builder() | ||
.put(DismissEvent.EVENT_NAME, MapBuilder.of("registrationName", "onDismiss")) | ||
.build(); | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
ReactAndroid/src/main/java/com/facebook/react/views/modalhost/ReactModalHostView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
package com.facebook.react.views.modalhost; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: add a license header please |
||
|
||
import android.app.Dialog; | ||
import android.content.Context; | ||
import android.content.DialogInterface; | ||
import android.graphics.Color; | ||
import android.graphics.drawable.ColorDrawable; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.view.WindowManager; | ||
|
||
import com.facebook.react.common.annotations.VisibleForTesting; | ||
import com.facebook.react.views.view.ReactViewGroup; | ||
|
||
/** | ||
* A Modal view that works as a base ViewGroup to host other views. | ||
*/ | ||
public class ReactModalHostView extends ViewGroup { | ||
|
||
private ReactViewGroup mHostView; | ||
private Dialog mDialog; | ||
|
||
public ReactModalHostView(Context context) { | ||
super(context); | ||
|
||
mHostView = new ReactViewGroup(context); | ||
mHostView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); | ||
|
||
mDialog = new Dialog(context, android.R.style.Theme_DeviceDefault_Dialog_NoActionBar); | ||
mDialog.setContentView(mHostView); | ||
mDialog.show(); | ||
mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); | ||
mDialog.getWindow().setLayout( | ||
WindowManager.LayoutParams.MATCH_PARENT, | ||
WindowManager.LayoutParams.MATCH_PARENT); | ||
} | ||
|
||
public void setTransparent(boolean transparent) { | ||
if (transparent) { | ||
mDialog.getWindow().clearFlags( | ||
WindowManager.LayoutParams.FLAG_DIM_BEHIND); | ||
} else { | ||
mDialog.getWindow().setFlags( | ||
WindowManager.LayoutParams.FLAG_DIM_BEHIND, | ||
WindowManager.LayoutParams.FLAG_DIM_BEHIND); | ||
} | ||
} | ||
|
||
@Override | ||
protected void onLayout(boolean changed, int l, int t, int r, int b) { | ||
} | ||
|
||
@Override | ||
public void addView(View child, int index) { | ||
mHostView.addView(child, index); | ||
} | ||
|
||
@Override | ||
public int getChildCount() { | ||
return mHostView.getChildCount(); | ||
} | ||
|
||
@Override | ||
public View getChildAt(int index) { | ||
return mHostView.getChildAt(index); | ||
} | ||
|
||
@Override | ||
public void removeView(View child) { | ||
mHostView.removeView(child); | ||
} | ||
|
||
@Override | ||
public void removeViewAt(int index) { | ||
mHostView.removeViewAt(index); | ||
} | ||
|
||
@Override | ||
public void removeAllViews() { | ||
mHostView.removeAllViews(); | ||
} | ||
|
||
public void dismissModal() { | ||
mDialog.dismiss(); | ||
} | ||
|
||
/*package*/ void setOnDismissListener(DialogInterface.OnDismissListener listener) { | ||
mDialog.setOnDismissListener(listener); | ||
} | ||
|
||
@VisibleForTesting | ||
public Dialog getDialog() { | ||
return mDialog; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: add the BSC license header please