Skip to content
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

Implements feature to influence position of camera controls in horizontal mode #209

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fredrik-smedberg
Copy link

Tested using

  • iPad 12,9" (iOS 16.4)
  • Flutter 3.13.7
  • camera lib 0.10.5+5

Summary
This PR introduces an option for developers to align camera control widgets either to the left or right in horizontal mode for the flutter_wechat_camera_picker.

Description
At present, the flutter_wechat_camera_picker positions its camera control widgets to the left when operated in horizontal mode. This alignment contrasts with the native iOS camera preview view, which aligns its controls to the right. It's possible that this leftward alignment might be the default for most WeChat-related components. I personally favor the native iOS style, with the controls on the right. Previously, the only workaround was to set cameraQuarterTurns to 2, which would align the controls to the right but in an upside-down manner. This PR offers a more streamlined solution, enabling developers to decide the preferred alignment for the camera controls.

…amera controls in horizontal mode based on the user's dominant hand.
Copy link
Member

@AlexV525 AlexV525 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late review. I like the general idea.

@@ -5,3 +5,5 @@
/// Two types for the viewer: image and video.
/// 两种预览类型:图片和视频
enum CameraPickerViewType { image, video }

enum DominantHand { left, right }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need docs here, make it as a template so the config can ref it directly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please give me an example, as I'm not sure what to do?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Define:

/// {@template wechat_camera_picker.ForegroundBuilder}
/// Build the foreground/overlay widget with the given [CameraValue].
/// 根据给定的 [CameraValue] 构建自定义的前景 widget
///
/// The `controller` will be null until initialized.
/// 在 [CameraController] 完成初始化前,`controller` 将为空。
/// {@endtemplate}

Use:
/// {@macro wechat_camera_picker.ForegroundBuilder}

@@ -1635,6 +1635,14 @@ class CameraPickerState extends State<CameraPicker>
);
}

TextDirection determineTextDirection(Enum orientation, DominantHand hand) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs too.

@@ -1635,6 +1635,14 @@ class CameraPickerState extends State<CameraPicker>
);
}

TextDirection determineTextDirection(Enum orientation, DominantHand hand) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use DeviceOrientation instead of Enum?

Copy link
Author

@fredrik-smedberg fredrik-smedberg Oct 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my initial thought too, but the code on line 1652 cause issues, specifically:
final orientation = deviceOrientation ?? MediaQuery.of(context).orientation
it's a bit tricky. deviceOrientation is enum of type DeviceOrientation, but MediaQuery.of(context).orientation is enum of type Orientation. The type for final orientation is therefore Enum. DeviceOrientation (four values) doesn't inherit from Orientation (two values).

I realise now that my determineTextDirection will crash if the MediaQuery-method's values are returned. I'll update my code, and then await your feedback on this to see if I should refactor more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turn those values into string so you don't need an Enum, like what we've already did.

@@ -1635,6 +1635,14 @@ class CameraPickerState extends State<CameraPicker>
);
}

TextDirection determineTextDirection(Enum orientation, DominantHand hand) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name determineTextDirection was not straightforward to understand which part of UI it handles. Consider making it inlined or a more general name.

? TextDirection.rtl
: TextDirection.ltr,
textDirection:
determineTextDirection(orientation, pickerConfig.dominantHand),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the trailing comma here.

@AlexV525 AlexV525 marked this pull request as draft December 7, 2023 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants