我需要对两个景观位置之间的方向变化应用不同的样式,即React Native中的landscapeRight到landscapeLeft或反之亦然?我知道如何在人像和风景之间进行检测,只需要在REACT NATIVE中两个风景位置之间有一个听众! 谢谢!
答案 0 :(得分:1)
您将必须使用外部依赖项来管理它。 SELECT *
FROM dbo.tables
WHERE ID = 18
AND DateTime BETWEEN CONVERT(DATETIME, '2019-03-01 00:00:00')
AND CONVERT(DATETIME, '2019-03-31 00:00:00')
AND DATEPART(mi, datetime) % 5 = 0
之类的东西可以为您提供想要的东西。此选项要求您使用完整的react-native-orientation-locker
项目,因为它需要您链接本机代码,因此它将在react-native
中不起作用。您可以详细了解here。以下是仓库中的基本用法说明。
您可以通过以下方式安装它:
Expo
链接后,还需要执行一些额外的步骤。
在项目的npm install react-native-orientation-locker --save
react-native link react-native-orientation-locker
中添加以下内容:
AppDelegate.m
安卓系统
将以下内容添加到android / app / src / main / AndroidManifest.xml
+#import "Orientation.h"
@implementation AppDelegate
// ...
+- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
+ return [Orientation getOrientation];
+}
@end
实施onConfigurationChanged方法(在<activity
....
+ android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
....
</activity>
中)
MainActivity.java
然后,您可以在想要访问方向的位置设置一个侦听器,通常将其添加到// ...
+import android.content.Intent;
+import android.content.res.Configuration;
public class MainActivity extends ReactActivity {
+ @Override
+ public void onConfigurationChanged(Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+ Intent intent = new Intent("onConfigurationChanged");
+ intent.putExtra("newConfig", newConfig);
+ this.sendBroadcast(intent);
+ }
// ......
}
中,然后将其移到componentDidMount
中。
这是一些示例代码,您可以用来设置它。
componentWillUnmount
这意味着在您的import Orientation from 'react-native-orientation-locker';
_onOrientationDidChange = (orientation) => {
if (orientation === 'LANDSCAPE-LEFT') {
//do something with landscape left layout
}
if (orientation === 'LANDSCAPE-RIGHT') {
//do something with landscape right layout
}
};
componentWillMount() {
//The getOrientation method is async. It happens sometimes that
//you need the orientation at the moment the js starts running on device.
//getInitialOrientation returns directly because its a constant set at the
//beginning of the js code.
var initial = Orientation.getInitialOrientation();
if (initial === 'PORTRAIT') {
//do stuff
} else {
//do other stuff
}
},
componentDidMount() {
Orientation.getAutoRotateState((rotationLock) => this.setState({rotationLock}));
//this allows to check if the system autolock is enabled or not.
Orientation.lockToPortrait(); //this will lock the view to Portrait
//Orientation.lockToLandscapeLeft(); //this will lock the view to Landscape
//Orientation.unlockAllOrientations(); //this will unlock the view to all Orientations
//get current UI orientation
/*
Orientation.getOrientation((orientation)=> {
console.log("Current UI Orientation: ", orientation);
});
//get current device orientation
Orientation.getDeviceOrientation((deviceOrientation)=> {
console.log("Current Device Orientation: ", deviceOrientation);
});
*/
Orientation.addOrientationListener(this._onOrientationDidChange);
},
componentWillUnmount () {
Orientation.removeOrientationListener(this._onOrientationDidChange);
}
函数中,它将收到以下内容之一:
_onOrientationDidChange
'PORTRAIT'
相机左侧的主页按钮向右'LANDSCAPE-LEFT'
右侧的相机主页按钮'LANDSCAPE-RIGHT'
'PORTRAIT-UPSIDEDOWN'