Skip to content

Commit 63314e1

Browse files
committed
Update Fragment
1 parent 998b46e commit 63314e1

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

Demo/app/src/main/java/com/pureswift/swiftandroid/Fragment.kt

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,28 @@ import android.os.Bundle
44
import android.view.LayoutInflater
55
import android.view.View
66
import android.view.ViewGroup
7+
import android.widget.LinearLayout
78

89
class Fragment(val swiftObject: SwiftObject): android.app.Fragment() {
910

1011
@Deprecated("Deprecated in Java")
11-
external override fun onCreateView(
12+
override fun onCreateView(
1213
inflater: LayoutInflater,
1314
container: ViewGroup?,
14-
savedInstanceState: Bundle
15-
): View?
15+
savedInstanceState: Bundle?
16+
): View? {
17+
val context = this.context
18+
checkNotNull(context)
19+
val view = this.onCreateViewSwift(inflater, container, savedInstanceState)
20+
checkNotNull(view)
21+
val linearLayout = LinearLayout(context)
22+
linearLayout.addView(view)
23+
return view
24+
}
25+
26+
external fun onCreateViewSwift(
27+
inflater: LayoutInflater,
28+
container: ViewGroup?,
29+
savedInstanceState: Bundle?
30+
): View
1631
}

Demo/app/src/main/swift/Fragment.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@ public extension Fragment {
2121

2222
struct Callback {
2323

24-
var onCreateView: ((AndroidView.LayoutInflater?, AndroidView.ViewGroup?, AndroidOS.Bundle?) -> (AndroidView.View?))?
24+
var onCreateView: ((AndroidView.LayoutInflater?, AndroidView.ViewGroup?, AndroidOS.Bundle?) -> (AndroidView.View))
2525
}
2626
}
2727

2828
@JavaImplementation("com.pureswift.swiftandroid.Fragment")
2929
extension Fragment {
3030

3131
@JavaMethod
32-
func onCreateView(
32+
func onCreateViewSwift(
3333
inflater: AndroidView.LayoutInflater?,
3434
container: AndroidView.ViewGroup?,
3535
savedInstanceState: AndroidOS.Bundle?
3636
) -> AndroidView.View? {
3737
log("\(self).\(#function)")
38-
return callback.onCreateView?(inflater, container, savedInstanceState)
38+
return callback.onCreateView(inflater, container, savedInstanceState)
3939
}
4040
}
4141

0 commit comments

Comments
 (0)