Skip to content

Commit

Permalink
Add componentName in modalDismissed event. (#5846)
Browse files Browse the repository at this point in the history
* [iOS] Added componentName to be passed to modalDismissedEvent

* Added componentName to the ModalDismissedEvent type.

* Updated the JS test.

* Updated the Playground Podfile.lock.

* Updated the doc.

* Fixed dismissedMultipleModals not having a name.

* Made componentName optional for ModalDismissedEvent.

* Initial Android implementation

* Revert Android e2e emulator name

* Revert iOS Podfile

* Podfile

* Setting OCMock to 3.4.3

* Fixed the documentation.

* Fixed requested changes

* Updated the doc.

* Now emitting componentName for dismissAllModals event.

* Retriggering build

* Revert

* Move all topBar.title options to topBarTitlePresenter (#5883)

Fix TopBar title animation. This commit changes how RNN handles title and subtitle.
Until now, RNN created a custom view for title and subtitle which interfered with the way the system animated the TopBar title.
With this commit the custom view is created only when both subtitle and title are declared, otherwise RNN uses the system behavior.

* make dotIndicator to respect visible value (#5884)

In Android dotIndicator with initial value of visible: false is not respected and the dot appears in any case.

Co-authored-by: Guy Carmeli <[email protected]>

* Update default value for fontsize in navigation title and subtitle (#5868)

Co-authored-by: Yogev Ben David <[email protected]>

* v0.62 Support (#5795)

react native 0.62 Support

* Fix bottomTab merging options with default (#5885)

When updating bottomTab options with mergeOptions - default options were not taken into account and therefore were not applied to the newly created tabBarItem

* Update package.json version to 4.6.1 [ci skip]

* Update package.json version to 4.7.0 [ci skip]

* Fix external components layout

* Move selectTabOnPress prop to correct interface (#5894)

* Update changelog

* External components fixes (#5896)

* Fix external components layout

* Fix external component navigationItem options resolving

* f

* Update package.json version to 4.7.1 [ci skip]

* Official Gradle Wrapper Validation Action (#5901)

See: https://github.com/gradle/wrapper-validation-action

* temporarily disable workflows

* Support react-native-youtube (#5903)

react-native-youtubte is a popular library which wraps the native youtube library. The native lib attempts to detect if the player is hidden behind other views in order to prevent developers from playing videos in the background.
Since the overlay container was always attached to hierarchy, the library stopped playback as it mistakingly detected the player was used in the background.

This commit simply attaches the overlay container only when needed so as long as no overlays are displayed, the lib can be used.

* apply extendedLayoutIncludesOpaqueBars true on all viewControllers (#5906)

* Update package.json version to 4.8.0 [ci skip]

* Fix overlays touch interception on new iPads (#5908)

* Fix NPE when showing Overlay (#5909)

Co-authored-by: Yogev Ben David <[email protected]>

* Update package.json version to 4.8.1 [ci skip]

* Update changelog

* Allow reset topBar.title.color when color isn't provided (#5910)

* Allow topBar.title.color reset when color isn't provided

* Reset to nil color

* Merge topBar options with default

* Fix topBar options merging

Co-authored-by: Guy Carmeli <[email protected]>

* Update package.json version to 4.8.2 [ci skip]

* Update package.json version to 4.8.3 [ci skip]

* Fix wallaby (#5917)

* Fix wallaby

* Add coverage on tsx files

* Update lib/src/commands/OptionsProcessor.test.ts

Co-authored-by: Guy Carmeli <[email protected]>

* Fix topBar options merging with default (#5918)

* Add missing function

* Update package.json version to 4.8.4 [ci skip]

* Update changelog

* v5 (#5931)

Merge v5 into master

Highlights of this release
* Easier installation
* autolink and reac-native link support
* Shared Element Transition - reimplemented from scratch and new API
* [iOS] showModal animation api parity
* [Android] Animation values are now declared in dp
* [iOS] deprecate topBar.drawBehind
* [Android] RNN is migrating to Kotlin

closes #5904

* Update package.json version to 5.0.0 [ci skip]

* Adapt installation guide to v5

* Update installation guide

Forgot to add Kotlin plugin

* Fix compilation issue when using react native 0.62

Fixes #5933

* Update package.json version to 5.0.1 [ci skip]

* Add deprecateDrawBehind option (#5934)

* Add deprecateDrawBehind option

* Apply draw behind options when deprecateDrawBehind equals false

Co-authored-by: Guy Carmeli <[email protected]>

* [v5][docs][showcases] starter kit (#5936)

Hey! I have updated RNN version to the latest one (5.0.1 by the time)
Hope someone will find it useful 🤩

* Add window.backgroundColor option (#5942)

* Update package.json version to 5.1.0 [ci skip]

* Fix crash when mergeOptions were called before stack view was created (#5945)

Co-authored-by: Yogev Ben David <[email protected]>

* Apply extendedLayoutIncludesOpaqueBars true on all viewControllers

* Update package.json version to 5.1.1 [ci skip]

* Update Android alert

* Fix custom push animations (#5947)

Custom push animations broke after refactoring Shared Element Transition.
Fixes #5943

* Layout background color (#5946)

* Apply layout.backgroundColor on parent view controllers

* Add layout.componentBackgroundColor

* Remove drawBehind deprecation

* Update package.json version to 6.0.0 [ci skip]

* Update changelog

* Fix applying drawBehind through mergeOptions (#5951)

mergeOptions did not handle bottomTabs.drawBehind options properly - the ReactRootView wasn't remeasured.

* Update package.json version to 6.0.1 [ci skip]

* Add slide animation to playground app

* [iOS] Added componentName to be passed to modalDismissedEvent

* Added componentName to the ModalDismissedEvent type.

* Updated the JS test.

* Updated the Playground Podfile.lock.

* Updated the doc.

* Fixed dismissedMultipleModals not having a name.

* Made componentName optional for ModalDismissedEvent.

* Initial Android implementation

* Revert Android e2e emulator name

* Revert iOS Podfile

* Podfile

* Setting OCMock to 3.4.3

* Fixed the documentation.

* Fixed requested changes

* Updated the doc.

* Now emitting componentName for dismissAllModals event.

* Retriggering build

* Revert

* Fix dismissedMultipleModals componentName

* Undo OCMock hard version

* Updated Podfile

Co-authored-by: Guy Carmeli <[email protected]>
Co-authored-by: Yogev Ben David <[email protected]>
Co-authored-by: Ioannis Tsampoulatidis <[email protected]>
Co-authored-by: Mary Jenel <[email protected]>
Co-authored-by: Jason Safaiyeh <[email protected]>
Co-authored-by: wixmobile <[email protected]>
Co-authored-by: Roberto Tatasciore <[email protected]>
Co-authored-by: Jonathan Leitschuh <[email protected]>
Co-authored-by: ʙ ᴀ ᴛ ʀ <[email protected]>
  • Loading branch information
10 people authored Feb 24, 2020
1 parent 69c225f commit 1c2558d
Show file tree
Hide file tree
Showing 21 changed files with 92 additions and 18 deletions.
30 changes: 29 additions & 1 deletion docs/docs/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,45 @@ commandCompletedListener.remove();
|**completionTime**|Timestamp when the command, and consecutive animations, completed.|

## registerModalDismissedListener

Invoked when modal dismissed.

```js
class MyComponent extends Component {

componentDidMount() {
this.navigationEventListener = Navigation.events().bindComponent(this);
}

componentWillUnmount() {
// Not mandatory
if (this.navigationEventListener) {
this.navigationEventListener.remove();
}
}

modalDismissed({ componentId, componentName, modalsDismissed }) {

}
}
```

This event can be observed globally as well:

```js
// Subscribe
const modalDismissedListener = Navigation.events().registerModalDismissedListener(({ componentId, modalsDismissed }) => {
const modalDismissedListener = Navigation.events().registerModalDismissedListener(({ componentId, componentName, modalsDismissed }) => {

});
...
// Unsubscribe
modalDismissedListener.remove();
```
| Parameter | Description |
|:--------------------:|:-----|
|**componentId**| Id of the dismissing modal|
|**componentName**|Registered name used when registering the component with `Navigation.registerComponent()`|
|**modalsDismissed**|Number of modals dismissed.|

## registerModalAttemptedToDismissListener(iOS 13+ only)
Invoked only on iOS pageSheet modal when swipeToDismiss flag is set to true and modal swiped down to dismiss.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ public void emitCommandCompleted(String commandName, String commandId, long comp
emit(CommandCompleted, event);
}

public void emitModalDismissed(String id, int modalsDismissed) {
public void emitModalDismissed(String id, String componentName, int modalsDismissed) {
WritableMap event = Arguments.createMap();
event.putString("componentId", id);
event.putString("componentName", componentName);
event.putInt("modalsDismissed", modalsDismissed);
emit(ModalDismissed, event);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public ComponentViewController(final Activity activity,
this.presenter = componentPresenter;
}

@Override
public String getCurrentComponentName() {
return this.componentName;
}

@Override
public void setDefaultOptions(Options defaultOptions) {
super.setDefaultOptions(defaultOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,9 @@ public void applyBottomInset() {
public int getBottomInset(ViewController child) {
return perform(getParentController(), 0, p -> p.getBottomInset(child));
}

@Override
public String getCurrentComponentName() {
return getCurrentChild().getCurrentComponentName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ public void sendOnNavigationButtonPressed(String buttonId) {
getView().sendOnNavigationButtonPressed(buttonId);
}

@Override
public String getCurrentComponentName() {
return button.component.name.get();
}

@NonNull
@Override
protected TitleBarReactButtonView createView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public void sendOnNavigationButtonPressed(String buttonId) {

}

@Override
public String getCurrentComponentName() {
return null;
}

public void setComponent(Component component) {
this.component = component;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public interface ViewVisibilityListener {
private ViewVisibilityListener viewVisibilityListener = new ViewVisibilityListenerAdapter();
protected FabPresenter fabOptionsPresenter;
private ViewControllerOverlay overlay;
@Nullable public abstract String getCurrentComponentName();

public boolean isDestroyed() {
return isDestroyed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ public void applyBottomInset() {
if (view != null) presenter.applyBottomInset(view, getBottomInset());
}

@Override
public String getCurrentComponentName() {
return externalComponent.name.get();
}

public FragmentActivity getActivity() {
return (FragmentActivity) super.getActivity();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public boolean dismissModal(String componentId, @Nullable ViewController root, C
CommandListenerAdapter onDismiss = new CommandListenerAdapter(listener) {
@Override
public void onSuccess(String childId) {
eventEmitter.emitModalDismissed(componentId, 1);
eventEmitter.emitModalDismissed(componentId, toDismiss.getCurrentComponentName(), 1);
super.onSuccess(componentId);
}
};
Expand All @@ -89,6 +89,7 @@ public void dismissAllModals(ViewController root, Options mergeOptions, CommandL
}

String topModalId = peek().getId();
String topModalName = peek().getCurrentComponentName();
int modalsDismissed = size();

peek().mergeOptions(mergeOptions);
Expand All @@ -98,7 +99,7 @@ public void dismissAllModals(ViewController root, Options mergeOptions, CommandL
dismissModal(modals.get(0).getId(), root, new CommandListenerAdapter(listener) {
@Override
public void onSuccess(String childId) {
eventEmitter.emitModalDismissed(topModalId, modalsDismissed);
eventEmitter.emitModalDismissed(topModalId, topModalName, modalsDismissed);
super.onSuccess(childId);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public void sendOnNavigationButtonPressed(String buttonId) {

}

@Override
public String getCurrentComponentName() {
return component.name.get();
}

public void setComponent(Component component) {
this.component = component;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ protected ReactInstanceManager createReactInstanceManager() {
protected DevBundleDownloadListener getDevBundleDownloadListener() {
return bundleListenerMediator;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public void applyBottomInset() {
if (view != null) presenter.applyBottomInset(view, getBottomInset());
}

@Override
public String getCurrentComponentName() {
return null;
}

public static class SimpleView extends ReactView implements ReactComponent {

public SimpleView(@NonNull Context context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ protected FrameLayout createView() {
public void sendOnNavigationButtonPressed(String buttonId) {

}

@Override
public String getCurrentComponentName() { return null; }
};
assertThat(myController.getView()).isEqualTo(otherView);
}
Expand Down Expand Up @@ -146,6 +149,9 @@ protected ViewGroup createView() {
public void sendOnNavigationButtonPressed(String buttonId) {

}

@Override
public String getCurrentComponentName() { return null; }
};
vc.onChildViewAdded(view, child);
verify(yellowBoxDelegate).onChildViewAdded(view, child);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void dismissModal_listenerAndEmitterAreInvokedWithGivenId() {
CommandListener listener = spy(new CommandListenerAdapter());
uut.dismissModal(modal4.getId(), root, listener);
verify(listener).onSuccess(modal4.getId());
verify(emitter).emitModalDismissed(modal4.getId(), 1);
verify(emitter).emitModalDismissed(modal4.getId(), modal4.getCurrentComponentName(), 1);
}

@SuppressWarnings("Convert2Lambda")
Expand Down
5 changes: 3 additions & 2 deletions lib/ios/RNNCommandsHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ - (void)assertReady {
#pragma mark - RNNModalManagerDelegate

- (void)dismissedModal:(UIViewController *)viewController {
[_eventEmitter sendModalsDismissedEvent:viewController.layoutInfo.componentId numberOfModalsDismissed:@(1)];
[_eventEmitter sendModalsDismissedEvent:viewController.layoutInfo.componentId componentName:viewController.layoutInfo.name numberOfModalsDismissed:@(1)];
}

- (void)attemptedToDismissModal:(UIViewController *)viewController {
Expand All @@ -361,7 +361,8 @@ - (void)attemptedToDismissModal:(UIViewController *)viewController {

- (void)dismissedMultipleModals:(NSArray *)viewControllers {
if (viewControllers && viewControllers.count) {
[_eventEmitter sendModalsDismissedEvent:((UIViewController *)viewControllers.lastObject).layoutInfo.componentId numberOfModalsDismissed:@(viewControllers.count)];
UIViewController* lastViewController = [viewControllers.lastObject presentedComponentViewController];
[_eventEmitter sendModalsDismissedEvent:lastViewController.layoutInfo.componentId componentName:lastViewController.layoutInfo.name numberOfModalsDismissed:@(viewControllers.count)];
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/ios/RNNEventEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

- (void)sendOnPreviewCompleted:(NSString *)componentId previewComponentId:(NSString *)previewComponentId;

- (void)sendModalsDismissedEvent:(NSString *)componentId numberOfModalsDismissed:(NSNumber *)modalsDismissed;
- (void)sendModalsDismissedEvent:(NSString *)componentId componentName:(NSString *)componentName numberOfModalsDismissed:(NSNumber *)modalsDismissed;

- (void)sendModalAttemptedToDismissEvent:(NSString *)componentId;

Expand Down
3 changes: 2 additions & 1 deletion lib/ios/RNNEventEmitter.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,10 @@ - (void)sendOnPreviewCompleted:(NSString *)componentId previewComponentId:(NSStr
}];
}

- (void)sendModalsDismissedEvent:(NSString *)componentId numberOfModalsDismissed:(NSNumber *)modalsDismissed {
- (void)sendModalsDismissedEvent:(NSString *)componentId componentName:(NSString *)componentName numberOfModalsDismissed:(NSNumber *)modalsDismissed {
[self send:ModalDismissed body:@{
@"componentId": componentId,
@"componentName": componentName,
@"modalsDismissed": modalsDismissed
}];
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/events/ComponentEventsObserver.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ describe('ComponentEventsObserver', () => {
expect(navigationButtonPressedFn).toHaveBeenCalledTimes(1);
expect(navigationButtonPressedFn).toHaveBeenCalledWith({ buttonId: 'myButtonId', componentId: 'myCompId' });

uut.notifyModalDismissed({ componentId: 'myCompId', modalsDismissed: 1 });
uut.notifyModalDismissed({ componentId: 'myCompId', componentName: 'myCompName', modalsDismissed: 1 });
expect(modalDismissedFn).toHaveBeenCalledTimes(1);
expect(modalDismissedFn).toHaveBeenLastCalledWith({ componentId: 'myCompId', modalsDismissed: 1 })
expect(modalDismissedFn).toHaveBeenLastCalledWith({ componentId: 'myCompId', componentName: 'myCompName', modalsDismissed: 1 })

uut.notifyModalAttemptedToDismiss({ componentId: 'myCompId' });
expect(modalAttemptedToDismissFn).toHaveBeenCalledTimes(1);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/interfaces/ComponentEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface NavigationButtonPressedEvent extends ComponentEvent {
}

export interface ModalDismissedEvent extends ComponentEvent {
componentId: string;
componentName: string;
modalsDismissed: number;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ - (void)testLayout_shouldExtendedLayoutIncludesOpaqueBars {
UIViewController* component = [[UIViewController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:nil];
UINavigationController* stack = [[UINavigationController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:nil];
UITabBarController* tabBar = [[UITabBarController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:nil];

XCTAssertTrue(component.extendedLayoutIncludesOpaqueBars);
XCTAssertTrue(stack.extendedLayoutIncludesOpaqueBars);
XCTAssertTrue(tabBar.extendedLayoutIncludesOpaqueBars);
Expand Down
8 changes: 4 additions & 4 deletions playground/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ PODS:
- ReactCommon/jscallinvoker (= 0.61.5)
- ReactNativeKeyboardTrackingView (5.6.1):
- React
- ReactNativeNavigation (5.0.0-alpha.14):
- ReactNativeNavigation (6.0.1):
- React
- React-RCTImage
- React-RCTText
Expand Down Expand Up @@ -260,7 +260,7 @@ DEPENDENCIES:
- Yoga (from `../../node_modules/react-native/ReactCommon/yoga`)

SPEC REPOS:
https://github.com/cocoapods/specs.git:
trunk:
- boost-for-react-native
- OCMock

Expand Down Expand Up @@ -348,9 +348,9 @@ SPEC CHECKSUMS:
React-RCTVibration: a49a1f42bf8f5acf1c3e297097517c6b3af377ad
ReactCommon: 198c7c8d3591f975e5431bec1b0b3b581aa1c5dd
ReactNativeKeyboardTrackingView: a240a6a0dba852bb107109a7ec7e98b884055977
ReactNativeNavigation: c14fd9c2ffd0ceb418065b97709c0497f38f9dcd
ReactNativeNavigation: 33657becf06c9c3a805ecb50dce8010fb887a1bb
Yoga: f2a7cd4280bfe2cca5a7aed98ba0eb3d1310f18b

PODFILE CHECKSUM: 781f49751a12b13af3e83d5dfc4b122aa5770543

COCOAPODS: 1.7.5
COCOAPODS: 1.8.4

0 comments on commit 1c2558d

Please sign in to comment.