Open
fix: 图片显示不全 #2
fix: 图片显示不全 #2
Open
easy_ghfAdd on Feb 27
Total: 4 files changed+169-150
@@ -13,12 +13,12 @@
13 * limitations under the License.13 * limitations under the License.
14 */14 */
15 15 
16-import { BreakpointType, BreakpointTypeEnum } from '../utils/BreakpointSystem';
17import { CommonConstants } from '../common/constants/CommonConstants';16import { CommonConstants } from '../common/constants/CommonConstants';
18import { Comment, CommentData } from '../model/CommentModel';17import { Comment, CommentData } from '../model/CommentModel';
18+import { mockData } from '../model/MockCommentData';
19+import { BreakpointType, BreakpointTypeEnum } from '../utils/BreakpointSystem';
19import { CommentInputDialog } from '../view/CommentInputDialog';20import { CommentInputDialog } from '../view/CommentInputDialog';
20import { CommentView } from '../view/CommentItemView';21import { CommentView } from '../view/CommentItemView';
21-import { mockData } from '../model/MockCommentData';
22 22 
23@Component23@Component
24export struct ImageCommentComponent {24export struct ImageCommentComponent {
@@ -60,145 +60,152 @@ export struct ImageCommentComponent {
60 }60 }
61 61 
62 build() {62 build() {
63- GridRow({63+ Column() {
64- columns: {64+ GridRow({
65- sm: 4,65+ columns: {
66- md: 10,
67- lg: 10
68- }
69- }) {
70- GridCol({
71- span: {
72 sm: 4,66 sm: 4,
73- md: 6,67+ md: 10,
74- lg: 668+ lg: 10
75 }69 }
76 }) {70 }) {
77- Column() {71+ GridCol({
72+ span: {
73+ sm: 4,
74+ md: 6,
75+ lg: 6
76+ }
77+ }) {
78 Column() {78 Column() {
79- Text($r('app.string.image_comment_title'))
80- .fontWeight(FontWeight.Bold)
81- .fontSize($r('sys.float.Title_L'))
82- .width('100%')
83- .fontColor($r('sys.color.font_primary'))
84- .padding({
85- left: new BreakpointType({
86- sm: $r('sys.float.padding_level8'),
87- md: $r('sys.float.padding_level12'),
88- lg: $r('sys.float.padding_level16')
89- }).getValue(this.curBp),
90- })
91- .margin({
92- top: $r('sys.float.padding_level32'),
93- bottom: $r('sys.float.padding_level6')
94- })
95- }
96- .padding({
97- top: this.statusBarHeight,
98- bottom: new BreakpointType({
99- sm: $r('sys.float.padding_level0'),
100- md: $r('sys.float.padding_level32'),
101- lg: $r('sys.float.padding_level16')
102- }).getValue(this.curBp),
103- })
104- 
105- Column() {
106- Image($r('app.media.launch_advert'))
107- .width('100%')
108- .aspectRatio(16 / 9)
109- .objectFit(ImageFit.Cover)
110- .borderRadius(new BreakpointType({ sm: 0, md: 16, lg: 16 }).getValue(this.curBp))
111- .padding({
112- left: new BreakpointType({
113- sm: $r('sys.float.padding_level6'),
114- md: $r('sys.float.padding_level12'),
115- lg: $r('sys.float.padding_level16')
116- }).getValue(this.curBp),
117- right: new BreakpointType({
118- sm: $r('sys.float.padding_level6'),
119- md: $r('sys.float.padding_level12'),
120- lg: $r('sys.float.padding_level16')
121- }).getValue(this.curBp)
122- })
123- }
124- }
125- .border({
126- width: {
127- right: new BreakpointType({
128- sm: $r('sys.float.padding_level0'),
129- md: $r('app.integer.border_width'),
130- lg: $r('app.integer.border_width')
131- }
132- ).getValue(this.curBp)
133- },
134- color: { right: $r('sys.color.comp_divider') }
135- })
136- .backgroundColor($r('sys.color.background_secondary'))
137- .height(new BreakpointType({ sm: '40%', md: '100%', lg: '100%' }).getValue(this.curBp))
138- }
139- 
140- GridCol({
141- span: {
142- sm: 4,
143- md: 4,
144- lg: 4
145- }
146- }) {
147- Flex({ direction: FlexDirection.Column }) {
148- Text($r('app.string.hot_comment'))
149- .height($r('app.integer.text_hot_comment_height'))
150- .width('100%')
151- .padding({ left: $r('sys.float.padding_level8') })
152- List() {
153- LazyForEach(this.commentList, (comment: Comment) => {
154- CommentView({ comment })
155- }, (item: string) => item);
156- }
157- .cachedCount(2)
158- .padding({
159- left: $r('sys.float.padding_level8'),
160- right: $r('sys.float.padding_level8')
161- })
162- .margin({ bottom: $r('sys.float.padding_level8') })
163- .scrollBar(BarState.Off)
164- .width('100%')
165- .flexGrow(1)
166- 
167- Row() {
168 Column() {79 Column() {
169- Text($r('app.string.text_input_hint'))80+ Text($r('app.string.image_comment_title'))
170- .fontColor($r('sys.color.font_secondary'))81+ .fontWeight(FontWeight.Bold)
171- .borderRadius($r('app.integer.text_input_hint_border_radius'))82+ .fontSize(this.curBp === BreakpointTypeEnum.SM ? $r('sys.float.Title_S') : $r('sys.float.Title_L'))
172- .height($r('app.integer.text_input_hint_height'))
173 .width('100%')83 .width('100%')
174- .padding({ left: $r('sys.float.padding_level8') })84+ .fontColor($r('sys.color.font_primary'))
175- .backgroundColor($r('sys.color.comp_background_tertiary'))85+ .padding({
176- .onClick(() => {86+ left: new BreakpointType({
177- if (this.dialogController !== null) {87+ sm: $r('sys.float.padding_level8'),
178- this.dialogController.open();88+ md: $r('sys.float.padding_level12'),
179- }89+ lg: $r('sys.float.padding_level16')
90+ }).getValue(this.curBp),
91+ })
92+ .margin({
93+ top: new BreakpointType({
94+ sm: $r('sys.float.padding_level6'),
95+ md: $r('sys.float.padding_level32'),
96+ lg: $r('sys.float.padding_level32')
97+ }).getValue(this.curBp),
98+ bottom: $r('sys.float.padding_level6')
180 })99 })
181 }100 }
182 .padding({101 .padding({
183- left: $r('sys.float.padding_level8'),102+ top: this.statusBarHeight,
184- right: $r('sys.float.padding_level8'),103+ bottom: new BreakpointType({
185- bottom: this.navigatorBarHeight104+ sm: $r('sys.float.padding_level0'),
105+ md: $r('sys.float.padding_level32'),
106+ lg: $r('sys.float.padding_level16')
107+ }).getValue(this.curBp),
108+ })
109+ 
110+ Column() {
111+ Image($r('app.media.launch_advert'))
112+ .width('100%')
113+ .objectFit(ImageFit.Contain)
114+ .borderRadius(new BreakpointType({ sm: 0, md: 16, lg: 16 }).getValue(this.curBp))
115+ }
116+ .padding({
117+ left: new BreakpointType({
118+ sm: $r('sys.float.padding_level8'),
119+ md: $r('sys.float.padding_level12'),
120+ lg: $r('sys.float.padding_level16')
121+ }).getValue(this.curBp),
122+ right: new BreakpointType({
123+ sm: $r('sys.float.padding_level8'),
124+ md: $r('sys.float.padding_level12'),
125+ lg: $r('sys.float.padding_level16')
126+ }).getValue(this.curBp)
186 })127 })
187 }128 }
188- .alignItems(VerticalAlign.Center)
189- .justifyContent(FlexAlign.Center)
190- .height(new BreakpointType({ sm: 96, md: 76, lg: 76 }).getValue(this.curBp))
191- .width('100%')
192 .border({129 .border({
193- width: { top: $r('app.integer.border_width') },130+ width: {
194- color: { top: $r('sys.color.comp_divider') }131+ right: new BreakpointType({
132+ sm: $r('sys.float.padding_level0'),
133+ md: $r('app.integer.border_width'),
134+ lg: $r('app.integer.border_width')
135+ }
136+ ).getValue(this.curBp)
137+ },
138+ color: { right: $r('sys.color.comp_divider') }
195 })139 })
196- .padding({ top: $r('sys.float.padding_level2') })140+ .backgroundColor($r('sys.color.background_secondary'))
141+ .height(new BreakpointType({ sm: 'auto', md: '100%', lg: '100%' }).getValue(this.curBp))
197 }142 }
198- .margin({ top: this.statusBarHeight })143+ 
144+ GridCol({
145+ span: {
146+ sm: 4,
147+ md: 4,
148+ lg: 4
149+ }
150+ }) {
151+ Flex({ direction: FlexDirection.Column }) {
152+ Text($r('app.string.hot_comment'))
153+ .height($r('app.integer.text_hot_comment_height'))
154+ .width('100%')
155+ .padding({ left: $r('sys.float.padding_level8') })
156+ List() {
157+ LazyForEach(this.commentList, (comment: Comment) => {
158+ CommentView({ comment })
159+ }, (item: string) => item);
160+ }
161+ .cachedCount(2)
162+ .padding({
163+ left: $r('sys.float.padding_level8'),
164+ right: $r('sys.float.padding_level8')
165+ })
166+ .margin({ bottom: $r('sys.float.padding_level8') })
167+ .scrollBar(BarState.Off)
168+ .width('100%')
169+ .flexGrow(1)
170+ 
171+ Row() {
172+ Column() {
173+ Text($r('app.string.text_input_hint'))
174+ .fontColor($r('sys.color.font_secondary'))
175+ .borderRadius($r('app.integer.text_input_hint_border_radius'))
176+ .height($r('app.integer.text_input_hint_height'))
177+ .width('100%')
178+ .padding({ left: $r('sys.float.padding_level8') })
179+ .backgroundColor($r('sys.color.comp_background_tertiary'))
180+ .onClick(() => {
181+ if (this.dialogController !== null) {
182+ this.dialogController.open();
183+ }
184+ })
185+ }
186+ .padding({
187+ left: $r('sys.float.padding_level8'),
188+ right: $r('sys.float.padding_level8'),
189+ bottom: this.navigatorBarHeight
190+ })
191+ }
192+ .alignItems(VerticalAlign.Center)
193+ .justifyContent(FlexAlign.Center)
194+ .height(new BreakpointType({ sm: 96, md: 76, lg: 76 }).getValue(this.curBp))
195+ .width('100%')
196+ .border({
197+ width: { top: $r('app.integer.border_width') },
198+ color: { top: $r('sys.color.comp_divider') }
199+ })
200+ .padding({ top: $r('sys.float.padding_level2') })
201+ }
202+ .margin({ top: this.curBp === BreakpointTypeEnum.SM ? $r('sys.float.padding_level6') : this.statusBarHeight })
203+ }
204+ .height('auto')
205+ .backgroundColor($r('sys.color.background_primary'))
199 }206 }
200- .height(new BreakpointType({ sm: '60%', md: '100%', lg: '100%' }).getValue(this.curBp))
201- .backgroundColor($r('sys.color.background_primary'))
202 }207 }
208+ .width('100%')
209+ .height('100%')
203 }210 }
204}211}
@@ -40,7 +40,11 @@ class BasicDataSource implements IDataSource {
40 }40 }
41 41 
42 public getData(index: number): Comment {42 public getData(index: number): Comment {
43- return this.originDataArray[index];43+ try {
44+ return this.originDataArray[index];
45+ } catch (err) {
46+ return new Comment('', '', '', [], '');
47+ }
44 }48 }
45 49 
46 registerDataChangeListener(listener: DataChangeListener): void {50 registerDataChangeListener(listener: DataChangeListener): void {
@@ -86,7 +90,7 @@ class BasicDataSource implements IDataSource {
86}90}
87 91 
88export class CommentData extends BasicDataSource {92export class CommentData extends BasicDataSource {
89- private comments: Array<Comment> = [];93+ private comments: Comment[] = [];
90 94 
91 totalCount(): number {95 totalCount(): number {
92 return this.comments.length;96 return this.comments.length;
@@ -37,8 +37,7 @@ export class WindowUtil {
37 public static requestFullScreen(): void {37 public static requestFullScreen(): void {
38 // Realize the immersive effect.38 // Realize the immersive effect.
39 try {39 try {
40- const promise: Promise<void> = WindowUtil.windowClass.setWindowLayoutFullScreen(true);40+ WindowUtil.windowClass.setWindowLayoutFullScreen(true).then(() => {
41- promise.then(() => {
42 Logger.info(TAG, 'Succeeded in setting the window layout to full-screen mode.');41 Logger.info(TAG, 'Succeeded in setting the window layout to full-screen mode.');
43 }).catch((err: BusinessError) => {42 }).catch((err: BusinessError) => {
44 Logger.error(TAG, `Failed to set the window layout to full-screen mode. Cause: ${err.code}`);43 Logger.error(TAG, `Failed to set the window layout to full-screen mode. Cause: ${err.code}`);
@@ -52,10 +51,15 @@ export class WindowUtil {
52 private static registerBreakPoint() {51 private static registerBreakPoint() {
53 BreakpointSystem.getInstance().updateWidthBp(WindowUtil.windowClass);52 BreakpointSystem.getInstance().updateWidthBp(WindowUtil.windowClass);
54 WindowUtil.updateAvoidArea(WindowUtil.windowClass);53 WindowUtil.updateAvoidArea(WindowUtil.windowClass);
55- WindowUtil.windowClass.on('windowSizeChange',54+ try {
56- () => BreakpointSystem.getInstance().onWindowSizeChange(WindowUtil.windowClass));55+ WindowUtil.windowClass.on('windowSizeChange',
57- WindowUtil.windowClass.on('avoidAreaChange',56+ () => BreakpointSystem.getInstance().onWindowSizeChange(WindowUtil.windowClass));
58- (avoidAreaOption) => WindowUtil.setAvoidArea(avoidAreaOption.type, avoidAreaOption.area));57+ WindowUtil.windowClass.on('avoidAreaChange',
58+ (avoidAreaOption) => WindowUtil.setAvoidArea(avoidAreaOption.type, avoidAreaOption.area));
59+ } catch (err) {
60+ Logger.error(TAG,
61+ `Failed to register windowSizeChange or avoidAreaChange. Cause: ${(err as BusinessError).code}`);
62+ }
59 }63 }
60 64 
61 public static unregisterBreakPoint(): void {65 public static unregisterBreakPoint(): void {
@@ -87,23 +87,27 @@ export struct CommentInputDialog {
87 .fontColor([$r('sys.color.icon_tertiary')])87 .fontColor([$r('sys.color.icon_tertiary')])
88 .fontSize($r('sys.float.Title_M'))88 .fontSize($r('sys.float.Title_M'))
89 .onClick(async () => {89 .onClick(async () => {
90- if (this.curBp === BreakpointTypeEnum.XL) {90+ try {
91- this.getUIContext().getPromptAction().showToast({91+ if (this.curBp === BreakpointTypeEnum.XL) {
92- message: $r('app.string.2in1_not_support'),92+ this.getUIContext().getPromptAction().showToast({
93- duration: CommonConstants.TOAST_DURATION,93+ message: $r('app.string.2in1_not_support'),
94- showMode: promptAction.ToastShowMode.DEFAULT,94+ duration: CommonConstants.TOAST_DURATION,
95- bottom: CommonConstants.TOAST_BOTTOM_MARGIN95+ showMode: promptAction.ToastShowMode.DEFAULT,
96- });96+ bottom: CommonConstants.TOAST_BOTTOM_MARGIN
97- } else {97+ });
98- if (this.selectedImages.length >= MAX_SELECT_IMAGE) {98+ } else {
99- this.getUIContext().getPromptAction().showToast({ message: $r('app.string.most_select_image') });99+ if (this.selectedImages.length >= MAX_SELECT_IMAGE) {
100- return;100+ this.getUIContext().getPromptAction().showToast({ message: $r('app.string.most_select_image') });
101- }101+ return;
102- const image: string =102+ }
103- await cameraCapture(this.getUIContext().getHostContext() as common.UIAbilityContext);103+ const image: string =
104- if (image !== '') {104+ await cameraCapture(this.getUIContext().getHostContext() as common.UIAbilityContext);
105- this.selectedImages.push(image);105+ if (image !== '') {
106+ this.selectedImages.push(image);
107+ }
106 }108 }
109+ } catch (err) {
110+ Logger.error(TAG, `Failed to capture image. Cause: ${err}`);
107 }111 }
108 })112 })
109 .margin({113 .margin({