-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Device Orientation Manipulation #133
Changes from 4 commits
4f9d94d
1cfc199
e37a429
78111e4
7bc9b52
d0c6f3b
41b24d9
582103f
8590f44
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
const fs = require('fs'); | ||
const _ = require('lodash'); | ||
const argparse = require('../utils/argparse'); | ||
const invoke = require('../invoke'); | ||
|
||
class Device { | ||
constructor(client, session, deviceConfig) { | ||
|
@@ -42,6 +43,16 @@ class Device { | |
await this.client.sendUserNotification(params); | ||
} | ||
|
||
async setOrientation(orientation) { | ||
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.
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. I see there are no unit tests here, the build will fail on lack of coverage. 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. 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. Okay, I will move it to |
||
// orientation is 'landscape' (meaning left side portrait) or 'portrait' (non-reversed) | ||
const call = invoke.call( | ||
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. you can invoke the EarlGrey functions directly instead 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. So I would do invoke.IOS.EarlGrey(
'rotateDeviceToOrientation:errorOrNil:',
invoke.IOS.UIDeviceOrientation(orientation)
); or how would it have to look like? 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. The ObjC code looks like this: [EarlGrey rotateDeviceToOrientation:UIDeviceOrientationLandscapeLeft errorOrNil:nil]; JS code pass Looking at typedef NS_ENUM(NSInteger, UIDeviceOrientation) {
UIDeviceOrientationUnknown,
UIDeviceOrientationPortrait, // Device oriented vertically, home button on the bottom
UIDeviceOrientationPortraitUpsideDown, // Device oriented vertically, home button on the top
UIDeviceOrientationLandscapeLeft, // Device oriented horizontally, home button on the right
UIDeviceOrientationLandscapeRight, // Device oriented horizontally, home button on the left
UIDeviceOrientationFaceUp, // Device oriented flat, face up
UIDeviceOrientationFaceDown // Device oriented flat, face down
} __TVOS_PROHIBITED; For I think this should work ... So it would look something like this: let invocation = invoke.IOS.EarlGrey(
'rotateDeviceToOrientation:errorOrNil:',
invoke.IOS.NSInteger(orientationEnum)
await invocationManager.execute(invocation);
); I hope it'll work :) 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. Hey, thanks for the insight, got it working without any native extension (yay 🎉 ). Though the call you describe doesn't work, it leads to an object like {
type: "EarlGrey",
value: "rotateDeviceToOrientation:errorOrNil:",
id: 5
} This leads to a "target is invalid" error, which, to me, looks a bit like a "bug", right? 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. I spent try my code, it's reasonable I mistaken. 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. Sure, I just wanted to state that calling invoke.IOS.EarlGrey(
'rotateDeviceToOrientation:errorOrNil:',
invoke.IOS.NSInteger(orientationEnum)
); would be the most readable and easiest way, I will try to make it work, the tests will tell me if I did something wrong then ;) |
||
invoke.IOS.EarlGrey(''), | ||
'rotateDeviceToOrientation:errorOrNil:', | ||
invoke.IOS.UIDeviceOrientation(orientation) | ||
); | ||
await new invoke.InvocationManager(this.client).execute(call); | ||
} | ||
|
||
async shutdown() { | ||
return await Promise.resolve(''); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,4 +28,28 @@ describe('Simulator', () => { | |
await element(by.label('Say Hello')).tap(); | ||
await expect(element(by.label('Hello!!!'))).toBeVisible(); | ||
}); | ||
|
||
describe('device orientation', () => { | ||
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. awesome stuff! |
||
beforeEach(async() => { | ||
await device.reloadReactNative(); | ||
await element(by.label('Orientation')).tap(); | ||
|
||
// Check if the element whichs input we will test actually exists | ||
await expect(element(by.id('currentOrientation'))).toExist(); | ||
}); | ||
|
||
it('OrientationLandscape', async () => { | ||
await device.setOrientation('landscape'); | ||
|
||
await expect(element(by.id('currentOrientation'))).toHaveText('Landscape'); | ||
}); | ||
|
||
it('OrientationPortrait', async() => { | ||
// As default is portrait we need to set it otherwise | ||
await device.setOrientation('landscape'); | ||
await device.setOrientation('portrait'); | ||
|
||
await expect(element(by.id('currentOrientation'))).toHaveText('Portrait'); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React, { Component } from 'react'; | ||
import { | ||
Text, | ||
View, | ||
TouchableOpacity | ||
} from 'react-native'; | ||
|
||
export default class Orientation extends Component { | ||
|
||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
horizontal: false | ||
}; | ||
console.log('Orientation react component constructed (console.log test)'); | ||
} | ||
|
||
detectHorizontal({nativeEvent: {layout: {width, height,x,y}}}) { | ||
this.setState({ | ||
horizontal: width > height | ||
}); | ||
} | ||
|
||
render() { | ||
return ( | ||
<View onLayout={this.detectHorizontal.bind(this)} style={{flex: 1, paddingTop: 20, justifyContent: 'flex-start', alignItems: 'center'}}> | ||
<Text testID="currentOrientation" style={{fontSize: 25, marginTop: 50}}> | ||
{this.state.horizontal ? 'Landscape' : 'Portrait'} | ||
</Text> | ||
</View> | ||
); | ||
} | ||
} |
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.
The main advantage of the remote invocation mechanism is that we don't need to add any other new call to the protocol
I believe we didn't make the invocation mechanism easily accessible for extension, and this is our fault.
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.
Does this mean I could have written
invoke.IOS.UIDeviceOrientation('UIDeviceOrientationLandscapeLeft')
or what would the JS call need to look like in this case?