Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/npm_and_yarn/yaml-and-commitlin…
Browse files Browse the repository at this point in the history
…t/cli-and-commitlint/prompt-cli-and-lint-staged-2.2.2
  • Loading branch information
open-hippy authored Jul 27, 2023
2 parents 2387a92 + 5045885 commit 69ff393
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 13 deletions.
15 changes: 15 additions & 0 deletions docs/en-us/hippy-react/native-event.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,18 @@ hippyEventEmitter.addListener('onSizeChanged', ({ oldWidth, oldHeight, width, he
console.log('size', oldWidth, oldHeight, width, height);
});
```

# System night mode change event

`Only supported by iOS, the minimum supported version is 2.16.6, (Note: The page will be recreated when Android modifies the night mode)`

This event is triggered when the system night mode changes

```jsx
import { HippyEventEmitter } from '@hippy/react';
const hippyEventEmitter = new HippyEventEmitter();
hippyEventEmitter. addListener('onNightModeChanged', ({ NightMode, RootViewTag }) => {
// NightMode: whether the current night mode, the value is 0 or 1; RootViewTag: the Tag of the HippyRootView that sends the event
console.log(`onDarkModeChanged: ${NightMode}, rootViewTag: ${RootViewTag}`);
});
```
13 changes: 13 additions & 0 deletions docs/en-us/hippy-vue/native-event.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,16 @@ app.$on('onSizeChanged', ({ oldWidth, oldHeight, width, height }) => {
console.log('size', oldWidth, oldHeight, width, height);
});
```

# System night mode change event

`Only supported by iOS, the minimum supported version is 2.16.6, (Note: The page will be recreated when Android modifies the night mode)`

This event is triggered when the system night mode changes

```jsx
app.$on('onNightModeChanged', ({ NightMode, RootViewTag }) => {
// NightMode: whether the current night mode, the value is 0 or 1; RootViewTag: the Tag of the HippyRootView that sends the event
console.log(`onDarkModeChanged: ${NightMode}, rootViewTag: ${RootViewTag}`);
});
```
15 changes: 15 additions & 0 deletions docs/hippy-react/native-event.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,18 @@ hippyEventEmitter.addListener('onSizeChanged', ({ oldWidth, oldHeight, width, he
console.log('size', oldWidth, oldHeight, width, height);
});
```

# 系统夜间模式改变事件

`仅iOS支持,最低支持版本 2.16.6,(注:Android修改夜间模式时页面将被重新创建)`

在当系统夜间模式发生改变时,会触发该事件

```jsx
import { HippyEventEmitter } from '@hippy/react';
const hippyEventEmitter = new HippyEventEmitter();
hippyEventEmitter.addListener('onNightModeChanged', ({ NightMode, RootViewTag }) => {
// NightMode: 当前是否夜间模式,取值0或1;RootViewTag: 发送事件的HippyRootView的Tag
console.log(`onDarkModeChanged: ${NightMode}, rootViewTag: ${RootViewTag}`);
});
```
13 changes: 13 additions & 0 deletions docs/hippy-vue/native-event.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,16 @@ app.$on('onSizeChanged', ({ oldWidth, oldHeight, width, height }) => {
console.log('size', oldWidth, oldHeight, width, height);
});
```

# 系统夜间模式改变事件

`仅iOS支持,最低支持版本 2.16.6,(注:Android修改夜间模式时页面将被重新创建)`

在当系统夜间模式发生改变时,会触发该事件

```jsx
app.$on('onNightModeChanged', ({ NightMode, RootViewTag }) => {
// NightMode: 当前是否夜间模式,取值0或1;RootViewTag: 发送事件的HippyRootView的Tag
console.log(`onDarkModeChanged: ${NightMode}, rootViewTag: ${RootViewTag}`);
});
```
21 changes: 15 additions & 6 deletions ios/sdk/base/HippyBatchedBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@
#import "HippyBundleURLProvider.h"
#import "HippyTurboModuleManager.h"
#import "HippyDeviceBaseInfo.h"
#import "HippyEventDispatcher.h"
#import <sys/utsname.h>
#include "core/scope.h"
#import "core/scope.h"


#define HippyAssertJSThread() // TODO: add assert imp
Expand All @@ -54,7 +55,7 @@
static NSString *const HippyNativeGlobalKeyAppVersion = @"AppVersion";
static NSString *const HippyNativeGlobalKeyDimensions = @"Dimensions";
static NSString *const HippyNativeGlobalKeyLocalization = @"Localization";
NSString *const HippyNativeGlobalKeyNightMode = @"NightMode";
static NSString *const HippyNativeGlobalKeyNightMode = @"NightMode";


/**
Expand Down Expand Up @@ -1235,11 +1236,19 @@ - (void)updateNativeInfoToHippyGlobalObject:(NSDictionary *)nativeInfo {
[self.javaScriptExecutor updateNativeInfoToHippyGlobalObject:nativeInfo];
}

- (void)setOSNightMode:(BOOL)isOSNightMode notifyToJS:(BOOL)shouldNotify {
static NSString *const hippyOnNightModeChangedEvent = @"onNightModeChanged";
static NSString *const hippyOnNightModeChangedParam1 = @"NightMode";
static NSString *const hippyOnNightModeChangedParam2 = @"RootViewTag";

- (void)setOSNightMode:(BOOL)isOSNightMode withRootViewTag:(nonnull NSNumber *)rootViewTag {
_isOSNightMode = isOSNightMode;
if (shouldNotify) {
[self updateNativeInfoToHippyGlobalObject:@{HippyNativeGlobalKeyNightMode: @(isOSNightMode)}];
}
// notify to js side
[self updateNativeInfoToHippyGlobalObject:@{HippyNativeGlobalKeyNightMode: @(isOSNightMode)}];
NSDictionary *args = @{@"eventName": hippyOnNightModeChangedEvent,
@"extra": @{ hippyOnNightModeChangedParam1 : @(isOSNightMode),
hippyOnNightModeChangedParam2 : rootViewTag } };
[self.parentBridge.eventDispatcher dispatchEvent:@"EventDispatcher"
methodName:@"receiveNativeEvent" args:args];
}

@end
2 changes: 0 additions & 2 deletions ios/sdk/base/HippyBridge+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
#import "HippyBridge.h"
#import "HippyJavaScriptExecutor.h"

FOUNDATION_EXTERN NSString *const HippyNativeGlobalKeyNightMode;

@class HippyModuleData;
@protocol HippyJavaScriptExecutor;

Expand Down
4 changes: 2 additions & 2 deletions ios/sdk/base/HippyBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ HIPPY_EXTERN NSString *HippyBridgeModuleNameForClass(Class bridgeModuleClass);

/// update `NightMode` state when changed
/// - Parameter isOSNightMode: bool
/// - Parameter shouldNotify: should notify js side or not
- (void)setOSNightMode:(BOOL)isOSNightMode notifyToJS:(BOOL)shouldNotify;
/// - Parameter rootViewTag: rootView's hippyTag
- (void)setOSNightMode:(BOOL)isOSNightMode withRootViewTag:(NSNumber *)rootViewTag;


#pragma mark - Turbo Module
Expand Down
4 changes: 2 additions & 2 deletions ios/sdk/base/HippyBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,8 @@ - (BOOL)isOSNightMode {
return self.batchedBridge.isOSNightMode;
}

- (void)setOSNightMode:(BOOL)isOSNightMode notifyToJS:(BOOL)shouldNotify {
[self.batchedBridge setOSNightMode:isOSNightMode notifyToJS:shouldNotify];
- (void)setOSNightMode:(BOOL)isOSNightMode withRootViewTag:(NSNumber *)rootViewTag {
[self.batchedBridge setOSNightMode:isOSNightMode withRootViewTag:rootViewTag];
}

#pragma mark -
Expand Down
2 changes: 1 addition & 1 deletion ios/sdk/base/HippyRootView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ - (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
if (currentStyle != previousTraitCollection.userInterfaceStyle) {
BOOL isNightMode = (UIUserInterfaceStyleDark == currentStyle);
if (self.bridge.isOSNightMode != isNightMode) {
[self.bridge setOSNightMode:isNightMode notifyToJS:YES];
[self.bridge setOSNightMode:isNightMode withRootViewTag:self.hippyTag];
}
}
}
Expand Down

0 comments on commit 69ff393

Please sign in to comment.